Starter quiz
- You can use multiple `elif` blocks.
- True ✓
- False
- A program calculates a theme park ticket price by first checking the users age and then checking if it is peak season or not. Which of the following is used in the program?
- single `if`
- `if-else`
- nested `if`s ✓
- `while` loop
-
- Match the relational operator to it's description.
- >⇔greater than ✓
- <⇔less than ✓
- !=⇔not equal to ✓
- ==⇔equal to ✓
- <=⇔less than or equal to ✓
- >=⇔more than or equal to ✓
- What will be the output of the following Python code? ```score = 50 if score >= 80: print("Win") elif grade >= 50: print("Try again") else: print("You lose")```
- Win
- Try again ✓
- You lose
-
- Which of the following statements about nested if statements is true?
- Nested `if` statements allow you to make more complex decisions within your code ✓
- You can only have one level of nesting in Python.
- Nested `if `statements execute all code blocks, regardless of the condition.
- Indentation is not important when using nested `if` statements.
-
- A school organises students based on age. Students 11-16 attend High School, and students 16-18 Sixth Form. Which expression correctly checks if a student's age falls within the High School range?
- age > 11 and age < 16
- age >= 11 and age <= 16
- age > 11 or age < 16 ✓
- age >= 11 or age <= 16
-
Exit quiz
- What does 'iteration' mean in programming?
- making choices based on conditions
- repeating a set of instructions multiple times ✓
- storing data that can change
- generating random values
-
- What is the purpose of a flag in programming?
- to store a number
- to indicate whether a specific condition has been met ✓
- to perform mathematical calculations
- to display output on the screen
-
- What while loop should you use if you want a block of code to run forever?
- `while True:` ✓
- `while Forever:`
- `while False:`
- `while x <10:`
-
- In Python, which of the following is a way to create a flag variable named `is_game_over` and set its initial value to `False`?
- `is_game_over = "False"`
- `is_game_over = False` ✓
- `is_game_over = 0`
- `is_game_over = "no"`
-
- What is treasure_found in this code? ```distance_traveled = 0 treasure_found = False while treasure_found == False: print(f"Keep going {distance_traveled} steps travelled so far")```
- an integer
- a flag ✓
- a loop
- user input
-
Worksheet
Loading worksheet ...
Presentation
Loading presentation ...
Video
Lesson Details
Key learning points
- Condition controlled iteration will execute until a condition is met.
- While loops are used for condition controlled iteration in Python.
- Flags can be used to start and stop a loop in a program.
Common misconception
A while loop is the most appropriate loop to use when you know exactly how many iterations will need to be performed.
While loops should be used when the number of iterations can change. Even though while loops can be used in this way, for loops are a more appropriate choice as they will track the number of iterations as part of their operation.
Keywords
Iteration - the process of repeating a sequence of instructions within a program loop
Condition - an expression that evaluates to True or False
Flag - a signal that is used to let a program know whether a condition has been met or not
+