diff --git a/bigos/lecture20250225/examScores01.py b/bigos/lecture20250225/examScores01.py new file mode 100644 index 0000000..05b4246 --- /dev/null +++ b/bigos/lecture20250225/examScores01.py @@ -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}") + diff --git a/bigos/lecture20250225/for01/for03.py b/bigos/lecture20250225/for01/for03.py index 55be419..3d44d64 100644 --- a/bigos/lecture20250225/for01/for03.py +++ b/bigos/lecture20250225/for01/for03.py @@ -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) diff --git a/bigos/lecture20250225/for01/for06.py b/bigos/lecture20250225/for01/for06.py index 5310393..ae343fe 100644 --- a/bigos/lecture20250225/for01/for06.py +++ b/bigos/lecture20250225/for01/for06.py @@ -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)) diff --git a/bigos/lecture20250225/lists01/list02.py b/bigos/lecture20250225/lists01/list02.py index d64f6e6..217c1ad 100644 --- a/bigos/lecture20250225/lists01/list02.py +++ b/bigos/lecture20250225/lists01/list02.py @@ -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 diff --git a/bigos/lecture20250225/lists01/lists01.py b/bigos/lecture20250225/lists01/lists01.py index 43ce084..e949c6c 100644 --- a/bigos/lecture20250225/lists01/lists01.py +++ b/bigos/lecture20250225/lists01/lists01.py @@ -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]) diff --git a/bigos/lecture20250225/lists01/names.py b/bigos/lecture20250225/lists01/names.py index e49823f..88248bd 100644 --- a/bigos/lecture20250225/lists01/names.py +++ b/bigos/lecture20250225/lists01/names.py @@ -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) diff --git a/bigos/lecture20250225/lists01/powers.py b/bigos/lecture20250225/lists01/powers.py index 747d005..a759e4c 100644 --- a/bigos/lecture20250225/lists01/powers.py +++ b/bigos/lecture20250225/lists01/powers.py @@ -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}")