Strings, lists and records · GCSE · OCR J277 2.2.3, AQA 8525 3.2.9, Edexcel 1CP2 6.6.1 · about 12 min
randint, choice and seeds: dice, random tunes and a robot that wanders.
[1 mark]Which values can random.randint(1, 6) give?
[1 mark]What does random.choice(["red", "green", "blue"]) give?
[1 mark]What does setting random.seed(42) before generating numbers do?
[1 mark]Write the AQA pseudo-code call for a random whole number from 1 to 10.
[1 mark]A dice program counts 600 rolls. About how many sixes should it see?
Roll a dice three times with random.randint(1, 6). For each roll, print roll: <n> and drive forward <n> * 5 cm. At the end print total: <cm> with the total distance, worked out from the rolls. This task fixes its random numbers, so you get the same rolls each run.
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() import random total = 0
Plan your program here, then type it in and press Run.