Why while loop is needed
📖 Scenario: Imagine you want to keep asking a friend if they want to play a game until they say yes. You don't know how many times you will need to ask. This is like a real-life situation where you repeat something until a condition is met.
🎯 Goal: You will build a simple program that keeps asking the user to enter the word yes. The program will stop only when the user types exactly yes. This shows why a while loop is useful for repeating actions until a condition is true.
📋 What You'll Learn
Create a variable called
answer and set it to an empty string ""Create a
while loop that runs as long as answer is not equal to "yes"Inside the loop, ask the user to type
"yes" using input() and store it in answerAfter the loop ends, print
"Thank you! You typed yes."💡 Why This Matters
🌍 Real World
While loops are used in many programs to keep doing something until a condition is met, like waiting for user input, checking sensor data, or repeating tasks.
💼 Career
Understanding while loops is important for programming jobs because many real-world problems need repeated actions that stop only when certain conditions happen.
Progress0 / 4 steps