Year 9 Computing — Procedures that take values and give one back
Read a procedure that is handed values to work on, and work out what a call to it gives.
Name: ________________________
1.A procedure named grow takes a number and gives back that number plus a tenth of it. Which of these calls gives 55?
- a) grow(60)
- b) grow(50)
- c) grow(55)
- d) grow(45)
2.One call sits inside another here. What number does it print?
def double(x): return x * 2 print(double(double(3)))3.This procedure doubles whatever it is handed. What number does it print?
def double(x): return x * 2 print(double(7))4.Two calls happen one after the other here. What number does it print?
def treble(x): return x * 3 a = treble(3) b = treble(a) print(b)5.A procedure named gap takes two numbers and gives back the first one take away the second. Exactly one of these calls gives 6. Which?
- a) gap(10, 4)
- b) gap(4, 6)
- c) gap(6, 6)
- d) gap(4, 10)
6.A procedure named step takes a number and gives back 100 take away that number multiplied by itself. Put these calls in order of the value each one gives, smallest first.
- step(7)
- step(2)
- step(3)
- step(5)
7.A procedure named area takes a length and a width and gives back one multiplied by the other. Match each call to the value it gives.
- area(3, 4)
- area(5, 5)
- area(2, 9)
- area(6, 7)
- area(1, 8)
- 8
- 12
- 18
- 42
- 25
8.This procedure has a loop inside it. What number does it print?
def upto(n): total = 0 for k in range(1, n + 1): total = total + k return total print(upto(5))
Answer key — Year 9 Computing — Procedures that take values and give one back
- 1. b) grow(50)
- 2. 12
- 3. 14
- 4. 27
- 5. a) gap(10, 4)
- 6. 1. step(7) 2. step(5) 3. step(3) 4. step(2)
- 7. area(3, 4) → 12; area(5, 5) → 25; area(2, 9) → 18; area(6, 7) → 42; area(1, 8) → 8
- 8. 15