0% found this document useful (0 votes)
2 views

Python Task 1

The document outlines ten programming scenarios that utilize while loops for various tasks, such as counting steps for a robot, guessing a number, and managing a countdown timer. Each scenario includes a brief description and hints for implementation, along with sample Python code. Additionally, there are challenges to enhance the basic functionalities, such as tracking attempts in the student login scenario.

Uploaded by

Zth Nthny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python Task 1

The document outlines ten programming scenarios that utilize while loops for various tasks, such as counting steps for a robot, guessing a number, and managing a countdown timer. Each scenario includes a brief description and hints for implementation, along with sample Python code. Additionally, there are challenges to enhance the basic functionalities, such as tracking attempts in the student login scenario.

Uploaded by

Zth Nthny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Counting Steps for a Robot


Scenario:
You are programming a robot to take 10 steps forward. Use a while loop to count
and print each step the robot takes.
💡 Extension: Make the robot say "Halfway there!" at step 5.

🎮 2. Game Guessing Number


Scenario:
A player has to guess a secret number (e.g., 7). The program keeps asking for
input until the correct number is guessed.
💬 Hint: Use input() and compare it with the target.

⏰ 3. Timer Countdown
Scenario:
You're building a countdown timer for a rocket launch. Start from 10 and count
down to 0 using a while loop.
🗣 Add: Print "Blast off!" when it reaches 0.

🍪 4. Cookie Jar
Scenario:
You have 5 cookies. Each time you eat one, the program tells you how many are
left. The loop runs until the cookies are all eaten.
😋 Add: Warn the user if they try to eat more than available.

💰 5. ATM PIN Entry


Scenario:
Allow the user 3 attempts to enter the correct PIN. If they enter it wrong 3 times,
block access.
🔐 Tip: Use a counter to keep track of attempts.

🚦 6. Traffic Light Check


Scenario:
Keep checking the traffic light status. If it’s “Red,” keep printing “Wait.” Once it’s
“Green,” print “Go!” and stop the loop.

🧮 7. Sum Until Zero


Scenario:
Ask the user to keep entering numbers. Stop when they enter 0. Then, display
the total sum of all the numbers entered.

🧹 8. Clean the Room


Scenario:
You are helping clean 10 dirty rooms. Use a while loop to print "Cleaning room
X..." until all rooms are clean.

📲 9. Mobile Battery Drain


Scenario:
Your mobile battery is at 100%. It drops 10% every hour. Use a while loop to
simulate this until it reaches 0%. Print battery status each hour.

🎓 10. Student Login


Scenario:
A student must log in using a correct password. Keep asking for the password
until the correct one is entered.

🧠 Challenge: Count how many attempts they took.


🔢 1. Counting Steps for a Robot
python
CopyEdit
step = 1
while step <= 10:
print(f"Step {step}")
if step == 5:
print("Halfway there!")
step += 1

🎮 2. Game Guessing Number


secret_number = 7
guess = int(input("Guess the number: "))
while guess != secret_number:
guess = int(input("Wrong! Try again: "))
print("Correct! You guessed it.")

⏰ 3. Timer Countdown
countdown = 10
while countdown >= 0:
print(countdown)
countdown -= 1
print("Blast off!")

🍪 4. Cookie Jar
cookies = 5
while cookies > 0:
print(f"Eating a cookie... {cookies} left")
cookies -= 1
print("No more cookies left!")

💰 5. ATM PIN Entry


correct_pin = "1234"
attempts = 0
pin = input("Enter your PIN: ")
while pin != correct_pin and attempts < 2:
attempts += 1
pin = input("Incorrect PIN. Try again: ")
if pin == correct_pin:
print("Access granted.")
else:
print("Card blocked.")

🚦 6. Traffic Light Check


light = input("Enter traffic light color (Red/Green): ")
while light.lower() != "green":
print("Wait...")
light = input("Enter traffic light color: ")
print("Go!")

🧮 7. Sum Until Zero


total = 0
number = int(input("Enter a number (0 to stop): "))
while number != 0:
total += number
number = int(input("Enter a number (0 to stop): "))
print(f"Total sum is {total}")

🧹 8. Clean the Room


room = 1
while room <= 10:
print(f"Cleaning room {room}...")
room += 1
print("All rooms are clean!")

📲 9. Mobile Battery Drain


battery = 100
while battery > 0:
print(f"Battery at {battery}%")
battery -= 10

print("Battery empty!")

🎓 10. Student Login


python
CopyEdit
password = "school123"
attempt = input("Enter password: ")
tries = 1

while attempt != password:


attempt = input("Wrong password. Try again: ")
tries += 1

print(f"Access granted after {tries} attempt(s).")

You might also like