Update 2/25/2025 lecture code
This commit is contained in:
parent
9ca384e858
commit
019b5788d1
7 changed files with 35 additions and 8 deletions
17
bigos/lecture20250225/examScores01.py
Normal file
17
bigos/lecture20250225/examScores01.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
|
||||
scoresList = [90.5, 87.2, 95, 100, 78, 88]
|
||||
#scoresList = [100, 100, 100, 100, 100, 100]
|
||||
|
||||
|
||||
numberOfScores = len(scoresList)
|
||||
scoresSum = 0
|
||||
|
||||
for scoreValue in scoresList:
|
||||
scoresSum = scoresSum + scoreValue
|
||||
print(f"value: {scoreValue} sum {scoresSum}")
|
||||
|
||||
scoreAverage = scoresSum / numberOfScores
|
||||
|
||||
print(f"Score sum is {scoresSum:.2f}")
|
||||
print(f"Score average is {scoreAverage:7.2f}")
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
print("\nSome demo range statements\n")
|
||||
|
||||
print("Print a range(6) ")
|
||||
for x in range(6):
|
||||
print(x)
|
||||
|
@ -15,7 +17,7 @@ for x in range(45, 55):
|
|||
print("Value of x = {:d}".format(x) )
|
||||
|
||||
|
||||
print("\n\nPrint a range(2, 30, 3) ")
|
||||
print("\n\nPrint a range(2, 30, 4) ")
|
||||
for x in range(2, 30, 4):
|
||||
print(x)
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
|
||||
# https://www.programiz.com/python-programming/for-loop
|
||||
digits = [70, 91, 85]
|
||||
scores = [70, 91, 85, 90, 100]
|
||||
|
||||
print(f"The length of this list of scores is {len(scores)}")
|
||||
|
||||
scoreSum = 0
|
||||
for i in digits:
|
||||
for i in scores:
|
||||
print(i)
|
||||
scoreSum += i
|
||||
else:
|
||||
print("The average is ",scoreSum/len(digits))
|
||||
print("The average is ",scoreSum/len(scores))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
|
||||
myList = [ 7, 5, 3, 9,11, 9999, "bob"]
|
||||
myList = [ 7, 5, 3, 9.5 ,11, 9999, "bob"]
|
||||
|
||||
|
||||
print("The list is ",myList)
|
||||
|
@ -10,7 +10,7 @@ print("\n")
|
|||
|
||||
counter = 0
|
||||
while(counter < len(myList)) :
|
||||
print(f"{counter} {myList[counter]} ")
|
||||
print(f"{counter} {myList[counter]} \t{type(myList[counter])}")
|
||||
counter = counter + 1
|
||||
|
||||
|
||||
|
|
|
@ -6,12 +6,13 @@ myList = [ 7, 5, 3, 9]
|
|||
print(myList)
|
||||
print(type(myList))
|
||||
|
||||
print( len(myList) )
|
||||
print( "Length of the list is ",len(myList) )
|
||||
|
||||
print(myList[0])
|
||||
print(myList[1])
|
||||
print(myList[2])
|
||||
print(myList[3])
|
||||
|
||||
|
||||
# This generates an error when you uncomment it
|
||||
#print(myList[4])
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
firstNames = [ "Harry", "Rusty", "Katrina", "Jack", "Gimli","Shenanigans", "Mandy"]
|
||||
|
||||
print(firstNames)
|
||||
print(len(firstNames))
|
||||
print("The length is ",len(firstNames))
|
||||
|
||||
for firstName in firstNames:
|
||||
print(firstName)
|
||||
|
|
|
@ -1,6 +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 powersList:
|
||||
powerOfTwo = 2**n
|
||||
print(f"{n:2d} {powerOfTwo:8d}")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue