Updated during lecture
This commit is contained in:
parent
3c88b102b2
commit
97b81f2b77
5 changed files with 56 additions and 2 deletions
|
@ -6,7 +6,7 @@ print(f"The length of this list of scores is {len(scores)}")
|
||||||
|
|
||||||
scoreSum = 0
|
scoreSum = 0
|
||||||
for i in scores:
|
for i in scores:
|
||||||
print(i)
|
|
||||||
scoreSum += i
|
scoreSum += i
|
||||||
|
print(i, scoreSum)
|
||||||
else:
|
else:
|
||||||
print("The average is ",scoreSum/len(scores))
|
print("The average is ",scoreSum/len(scores))
|
||||||
|
|
30
bigos/lecture20251007/for01/fordemo1.py
Normal file
30
bigos/lecture20251007/for01/fordemo1.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# For visualizing use this url
|
||||||
|
# https://pythontutor.com/visualize.html#mode=edit
|
||||||
|
|
||||||
|
myInt = 55
|
||||||
|
myFloat = 77
|
||||||
|
myList = [34, 99, 11, 7]
|
||||||
|
|
||||||
|
print(myList)
|
||||||
|
|
||||||
|
for listElement in myList:
|
||||||
|
print(listElement)
|
||||||
|
|
||||||
|
print("done")
|
||||||
|
|
||||||
|
|
||||||
|
# variation on the above
|
||||||
|
|
||||||
|
|
||||||
|
myInt = 55
|
||||||
|
myFloat = 77.
|
||||||
|
myList = [34, 99.7, 11, 7, "bob"]
|
||||||
|
|
||||||
|
print(myList)
|
||||||
|
|
||||||
|
for listElement in myList:
|
||||||
|
print(listElement)
|
||||||
|
|
||||||
|
print("done")
|
||||||
|
|
||||||
|
|
11
bigos/lecture20251007/lists01/powers2.py
Normal file
11
bigos/lecture20251007/lists01/powers2.py
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
|
||||||
|
#powersList = [0,1,2,3,4,5,6,7,8,9,10]
|
||||||
|
|
||||||
|
# Try this form
|
||||||
|
#powersList = range(0,11)
|
||||||
|
|
||||||
|
#print("The list is ", powersList)
|
||||||
|
|
||||||
|
for n in range(11):
|
||||||
|
powerOfTwo = 2**n
|
||||||
|
print(f"{n:2d} {powerOfTwo:8d}")
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
scoresList = [90.5, 87.2, 95, 100, 78, 88]
|
scoresList = [90.5, 87.2, 95, 100, 78, 88,87]
|
||||||
#scoresList = [100, 100, 100, 100, 100, 100]
|
#scoresList = [100, 100, 100, 100, 100, 100]
|
||||||
|
|
||||||
|
|
||||||
|
|
13
bigos/lecture20251007/while/while-Statement_0003.py
Normal file
13
bigos/lecture20251007/while/while-Statement_0003.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# while-Statement_0002.py
|
||||||
|
#
|
||||||
|
number = 1 # initialize variable 'number'
|
||||||
|
while(number <= 3): # execute the indented statements below while x less than or equal to 10.
|
||||||
|
length = float(input("Enter a value for the length: "))
|
||||||
|
if(length >0):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Invalid value. It must be > 0")
|
||||||
|
|
||||||
|
print(number, " : ", number) # print 'number' and number squared
|
||||||
|
number = number + 1 # replace number with number + 1
|
||||||
|
print("Done.") # print "Done." after dropping out of while loop.
|
Loading…
Add table
Add a link
Reference in a new issue