Programming basics · GCSE · OCR J277 2.2.1, AQA 8525 3.2.2, Edexcel 1CP2 6.3.2 · about 15 min
Storing, changing and naming values, and constants that never change.
[1 mark]What does this program print?
count = 0 count = count + 1 count = count + 1 print(count)
2
Each count = count + 1 works out the right-hand side with the current value, then stores the result back.
[1 mark]What does the = in speed = 60 mean?
[1 mark]Which of these are allowed as variable names?
Tick every answer that is true.
leg_lengthspeed22speedleg length[1 mark]speed = 60 then print(Speed). What happens?
[1 mark]What does this program print?
leg = 24 half = leg / 2 print(leg, half)
24 12.0
half stores the result of the calculation, and dividing gives a float.
[1 mark]Why store before = distance() before driving?
[1 mark]What is the difference between a variable and a constant?
[1 mark]Four drives all use MAX_SPEED. Why is that better than typing 40 four times?
Store 70 in a variable called speed. Print speed: 70 and half: 35, both using the variable (the number 70 appears only on the first line, and 35 nowhere). Dividing with / prints 35.0, which is not 35: // divides and keeps a whole number, and lesson F1.9 explains the difference. Then drive 20 cm at that speed.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
speed = 70
print("speed:", speed)The hint students can ask for: Put 70 in a variable called speed. Print speed: 70 and half: 35 using the variable, then drive 20 cm at that speed.
from bugbot import *
connect()
speed = 70
print('speed:', speed)
print('half:', speed // 2)
forward(speed, distance=20)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.