Starter quiz
- What is the term for repeating a sequence of instructions multiple times in a program?
- selection
- iteration ✓
- condition
- randomisation
-
- In Python, which code is used to create a loop that repeats as long as a condition is True?
- `if`
- `for`
- `while` ✓
- `else`
-
- What operator should be added to the gap to make the while loop run whilst the name entered is not equal to Sam? ```while name {operator here} "Sam":```
- ==
- =
- != ✓
- >=
-
- What is the primary purpose of a flag in programming?
- to store a numerical value
- to indicate whether a specific condition has been met ✓
- to perform mathematical calculations
- to display output on the screen.
-
- In a game, a player earns bonuses for collecting a certain number of coins. Which of the following would most likely cause a flag named bonus_earned to be set to True?
- The player loses a life.
- The player collects a set number of coins. ✓
- The player quits the game.
- The player completes a level.
-
- A flag can have two states ______ and False.
- 'True' ✓
Exit quiz
- Which logical operator in Python would you use to check if at least one of two conditions is True?
- `and`
- `or` ✓
- `not`
- `==`
-
- Which logical operator in Python would you use to check if both of two conditions are True?
- `and` ✓
- `or`
- `not`
- `=`
-
- Which of these Python `while` loop conditions will keep the loop running forever, no matter what happens inside the loop?
- `while count < 10:`
- `while user_input != "quit":`
- `while True:` ✓
- `while not game_over:`
-
- Which of the following is a potential benefit of combining programming structures?
- creating more complex programs ✓
- making code more concise and efficient ✓
- solving a wide range of problems ✓
- there is no need for variables
-
- What is the output of the following Python code? ``` is_weekend = True have_homework = False if is_weekend and not have_homework: print("Time to relax") else: print("Time to study.")```
- Time to relax ✓
- Time to study
- An error message will occur.
- No output will be produced.
-
Worksheet
Loading worksheet ...
Presentation
Loading presentation ...
Video
Lesson Details
Key learning points
- Expressions formed using logical operators evaluate to either True or False.
- Logical and relational operators can be combined to create complex conditions.
- The programming constructs of sequence, selection and iteration can be combined to make more complex programs.
Common misconception
Learners often get confused between the logic operators AND and OR.
For an AND statement to return True both inputs must be True. For an OR statement to return True either input can be True.
Keywords
Condition - an expression that evaluates to True or False
Selection - used when there is more than one possible path for a program to follow
Iteration - the process of repeating a sequence of instructions within a program loop
+