Words that join conditions
Answers are for parents and teachers.
1
Work out each result for x = 3 and y = 9: (a) x < 5 and y < 5 (b) x < 5 or y < 5 (c) not (x == 3).
Python
1x = 3 2y = 9
(a) True and False is False. (b) True or False is True. (c) not True is False.
2
Write a Python program: ask for a number. If it is between 10 and 20 (including both) print In range, otherwise print Out of range.
Model answer (lines are separated by /, and [indent] means four spaces at the start of the line): n = int(input("Number? ")) / if n >= 10 and n <= 20: / [indent] print("In range") / else: / [indent] print("Out of range")
3
A program should accept maybe, Maybe and MAYBE. Write the condition.
reply == "maybe" or reply == "Maybe" or reply == "MAYBE"
4
For each line say syntax, runtime or logic error: (a) if mark > 50 or mark < 100: to check that a mark is between 50 and 100 (b) if mark > 50 with no colon (c) print(total) when total was never set.
(a) logic error (b) syntax error (c) runtime error (NameError).
5
Explain why trace tables are useful when a program has and and or in the same condition.
They make you work out each small condition separately and then combine them in the right order, so you do not guess. Using test data for every branch shows mistakes.