Update lists

This commit is contained in:
Joe James
2020-02-25 08:16:53 -06:00
committed by GitHub
parent ea0956aea9
commit 88c6205eac

View File

@@ -2,19 +2,26 @@
# use square brackets to get one item of a list using index.
# note that first item has index 0.
# to get that first item, 67, scores[0]
scores = [67, 32, 29]
print(scores[2])
print() # print blank line
# sum is a function built into python lists.
# if all items in the list are numeric it will add them up.
# len gives you the number of items in the list, here 3 items.
print(sum(scores))
print(len(scores))
print()
# USING A FOR LOOP TO ITERATE A LIST
# our variable for the list is scores
# we use score as a variable for list iteration.
# each time through the loop, score takes on the next value in the list
for score in scores:
if score % 2 == 0:
if score % 2 == 0: # % is called mod, and gives you the remainder of a division
print(score, ' is even.')
print()