Functions and structured code · GCSE · OCR J277 2.2.3, AQA 8525 3.2.10, Edexcel 1CP2 6.6.2 · about 15 min
Information in and an answer out; procedures and functions.
[1 mark]What does this program print?
def double(n):
return n * 2
print(double(4))
print(double(10))[1 mark]In def square(size):, what is size?
[1 mark]What does this program print?
def greet(name, times):
for i in range(times):
print("hi", name)
greet("Ada", 2)[1 mark]What does this program print?
def double_print(n):
print(n * 2)
def double_return(n):
return n * 2
a = double_print(5)
b = double_return(5)
print(a, b)[1 mark]In area(20, 30), what are 20 and 30?
[1 mark]What is the difference between a function and a procedure?
[1 mark]What does this program print?
def check(n):
if n > 10:
return "big"
return "small"
print(check(15), check(3))Write polygon(sides, length) that prints polygon with <sides> sides and drives the shape. Call it for a pentagon (5 sides, 20 cm) and then a triangle (3 sides, 20 cm). Finish facing roughly the way you started.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def polygon(sides, length):
print("polygon with", sides, "sides")
# drive it
polygon(5, 20)Plan your program here, then type it in and press Run.
average(a, b, c) that returns the average of three numbers, and test it with values you can check.polygon a third parameter for the speed.creep(limit) that drives in 5 cm steps until the wall is under limit cm away, and returns how many steps it took.