Professional Documents
Culture Documents
Certainly
Certainly
A laboratory activity involving the use of `while` and `if` statements can be designed to help
students practice and understand the concepts of looping and conditional statements in programming.
Below is an example activity in the context of a simple Python program:
#### Objective:
#### Instructions:
1. **Introduction:**
2. **Task Description:**
- Ask students to create a Python program for a "Guess the Number" game.
- Provide feedback to the player if their guess is too high or too low.
- The game should continue until the player correctly guesses the number.
3. **Requirements:**
```python
import random
max_attempts = 10
attempts = 0
# Game loop
if guess == secret_number:
break
else:
attempts += 1
print(f"Sorry, you've run out of attempts. The correct number was {secret_number}.")
```
5. **Discussion:**
- Explore how the game flow changes based on the user's input.
6. **Extensions (Optional):**
Encourage students to run the program, test different scenarios, and modify the code to enhance their
understanding of `while` and `if` statements in Python.