☰ Year plan · Communication Technology

Lists and functions

Week 12 · Chapter 12 Programming (2): lists and functions in Python, with small programs that combine them · 3 lessons
Answers are for parents and teachers.
1
scores = [3, 9, 4]. Write the result of scores[0], scores[2], len(scores) and of scores[-1].
2
Trace this program in a table and write what it prints.
Python
1scores = [3, 9, 4]
2best = scores[0]
3for x in scores:
4    if x > best:
5        best = x
6print(best)
3
Write a function cube(n) that returns n * n * n, and write the value of cube(3).
4
Write what this program prints, and explain why the second line shows None.
Python
1def show(n):
2    print(n * n)
3
4r = show(5)
5print(r)
5
In the passed program, change the pass mark to 60. How many of [45, 72, 50, 38, 90] pass now?