Collections · Lesson 16 of 27
Lists
A list stores many values in one variable, in order.
marks = [78, 92, 65] print(marks[0]) # 78 indexes start at 0, like strings print(marks[-1]) # 65 print(len(marks)) # 3 marks[1] = 95 # lists can be changed print(marks) # [78, 95, 65]
Looping over a list:
for m in marks:
print(m)Useful built-in functions:
nums = [4, 9, 1] print(max(nums)) # 9 print(min(nums)) # 1 print(sum(nums)) # 14 print(9 in nums) # True
Your task
marks = [78, 92, 65, 88, 70] is given. Print, one per line:
- the highest mark
- the lowest mark
- the total
- the average (total divided by the number of marks)