What if your computer could keep trying until it gets it right, all by itself?
Why while loop is needed in Python - The Real Reasons
Imagine you want to keep asking a friend if they want to play a game until they say yes. You would have to keep repeating the question over and over manually.
Manually repeating the same question is tiring and easy to forget. If you want to ask 100 times, writing 100 lines is slow and full of mistakes.
The while loop lets the computer ask the question again and again automatically until the friend says yes. It saves time and avoids errors.
print('Do you want to play?') print('Do you want to play?') print('Do you want to play?') # repeated many times
ready = False while not ready: print('Do you want to play?')
It makes the computer repeat actions smoothly until a condition changes, like waiting for a yes or a stop signal.
Checking if a user entered the right password by asking again and again until the correct one is typed.
Manually repeating tasks is slow and error-prone.
While loops automate repetition based on conditions.
This helps programs wait or repeat actions until ready.