The break statement is used to exit a loop entirely, regardless of the loop's condition. Once Python encounters break, it immediately stops the loop and moves to the code that follows it. Unlike continue, which skips only the current iteration, break completely ends the loop.
Starting Value:
The program starts by setting current_number = 0.
Entering the Loop:
Since current_number < 10, Python enters the while loop.
Incrementing:
Inside the loop, current_number is increased by 1.
Ex: the first time through the loop, current_number becomes 1.
Checking the Condition:
The if statement checks if current_number equals 5.
If the condition is true, the break statement immediately stops the loop, and Python exits the loop.
Printing Numbers:
If current_number is not 5, the program prints the number and continues the loop.
In Python, the continue statement is used inside a loop to skip the rest of the code in the current iteration and immediately go back to the beginning of the loop. Instead of breaking out of the loop entirely (like break), it moves to the next iteration while still staying within the loop.
The program begins by setting current_number = 0.
Entering the Loop:
Since current_number < 10, Python enters the while loop.
Incrementing:
Inside the loop, current_number is increased by 1.
For example, the first time through the loop, current_number becomes 1.
Checking the Condition:
The if statement checks if current_number is divisible by 2 (i.e., current_number % 2 == 0).
If it is divisible by 2, the continue statement is triggered, skipping the print(current_number) line and jumping back to the top of the loop.
Printing Odd Numbers:
If current_number is not divisible by 2, Python skips the continue and executes the print(current_number) statement, printing the number.
Welcome, Future Evil Overlords (and Perry’s #1 Fans)!
Dr. Heinz Doofenshmirtz has trapped you in his Evil Trivia Quiz-inator! Answer his diabolical questions about Phineas and Ferb to prove you’re worthy of joining his evil empire… or at least not getting zapped by a random -inator.
Answer the Questions:
You’ll get 5 evil questions, each with 3 possible answers.
Type 1, 2, or 3 to pick your answer.
For example:
"What does Dr. Doofenshmirtz add to the name of every invention?"
1) inator
2)tronic
3)izer
4) Skip the Question
You Have 3 Chances
Start with 3 lives (❤️❤️❤️).
Wrong answer? Lose 1 life. Doof laughs.
0 lives = GAME OVER. Doof yells:"CURSE YOU, PERRY THE PLATYPUS!"
Special Commands:
skip
skips the question without losing a life
quit
Ends the game early. Doof Yells at you...
Win or Lose?
The game ends when you:
You answer all 5 questions → Victory!
You run out of lives → Defeat!
You quit → Doof disapproves.
The skills you need for this are:
while loops
break
continue
lists and list functions/methods
input and validation
list indexing
conditionals
if/elif/else
This program is deceptively hard. It may, in fact, be the most difficult program you've had. So, let's try and break it down to help you crush it...
questions = ["What is the name of Doofenshmirtz’s daughter?","Who is Doof's Robot Helper? "]
possible_answers = [["Vanessa", "Isabella", "Stacy", "Jenny"],["Ted", "Fred", "Bennie", "Norm"]]
correct_indices = [0, 3]
This works with a single for loop!!!
Be careful! You need to make sure all answers have 4 choices in order for this to work!!
[question, choice1, choice2, choice3, correct_number]
Example:
["What is the largest planet?", ["Earth", "Jupiter", "Mars"], 1],
You Need To Use a Nested List for this Method (Loop Inside a Loop)
[ question_text, answer_choices_list, correct_answer_index ]
Example:
["What is 2+2?", "3", "4", "5", 2]
You Can Use a Single Loop for This Method