Updated during lecture

This commit is contained in:
Edward Bigos 2025-10-07 10:39:32 -04:00
parent 3c88b102b2
commit 97b81f2b77
5 changed files with 56 additions and 2 deletions

View file

@ -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))

View 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")

View 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}")

View file

@ -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]

View 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.