1. A list of scores
A list keeps many values in order, inside square brackets: scores = [45, 12, 78].
scores[0]is the first item (counting starts at 0!),scores[-1]is the lastscores.append(33)adds 33 at the endlen(scores)is how many itemssum(scores),max(scores),min(scores)do the maths for you
You can loop over a list directly: for s in scores:.
scores = [45, 12, 78]
scores.append(33)
print(scores)
print("First:", scores[0], "Last:", scores[-1])
print("Matches:", len(scores), "Total:", sum(scores))
Challenge: Season scores
A batter’s scores (sample data) are in scores. She scored 61 in the latest match: append it. Then print, using len, sum and max:
Matches: 5Total: 229Highest: 78Average: 45.8(total ÷ matches)