Your algorithm is linear, there is no loops in there. So, the only place you need a loop is when you try to get correct response from the user. So, I'd propose you to move that into a function and then your example turns into this:

def get_user_input(prompt):
    while True:
        reply = input(prompt).replace(" ", "").lower()
        if reply in ['yes', 'no']:
            return reply
        print("Please enter YES or NO")

problem_exists = get_user_input("Do you have a problem in life? ")
if problem_exists == 'yes':
    action_possible = get_user_input("Do you have something to do about it? ")
print("Then why worry?")
Answer from rgezikov on Stack Overflow
🌐
Programiz
programiz.com › python-programming › while-loop
Python while Loop (With Examples)
while True: user_input = input("Enter password: ") # terminate the loop when user enters exit if user_input == 'exit': print(f'Status: Entry Rejected') break print(f'Status: Entry Allowed') Output · Enter password: Python is Fun Status: Entry Allowed Enter password: exit Status: Entry Rejected ...
🌐
ScholarHat
scholarhat.com › home
Python While Loop - Flowchart, Syntax with Example
September 11, 2025 - The Python while loop evaluates the condition. The condition may be any expression, and true is any non-zero value.
People also ask

What is a Python while loop, and when can I use it?
A while loop in Python is a concept or tool in which you write the particular condition that you want to execute repeatedly and it will get executed until the condition remains true. You can use the while loops when you do not know the exact number of repetitions of a particular problem
🌐
intellipaat.com
intellipaat.com › home › blog › python while loop
Python While Loop: Explained with While Loop Flowchart
Can I use else with a while loop in Python?
Yes, you can use else statements with a while loop in Python. Basically, the else statement will work only when the while loop ends naturally and not with a break statement.
🌐
intellipaat.com
intellipaat.com › home › blog › python while loop
Python While Loop: Explained with While Loop Flowchart
How does a while loop differ from a for loop in Python?
A for loop is generally preferred when you know the number of iterations of any conditions of the problem, whereas while loop is used when you are not sure about the number of iterations of that particular problem.
🌐
intellipaat.com
intellipaat.com › home › blog › python while loop
Python While Loop: Explained with While Loop Flowchart
🌐
TOOLSQA
toolsqa.com › python › python-while-loop
Python While Loop | While True and While Else in Python || ToolsQA
August 6, 2021 - ... Python "Do While" loops. The while loop in python is a way to run a code block until the condition returns true repeatedly. Unlike the "for" loop in python, the while loop does not initialize or increment the variable value automatically.
🌐
freeCodeCamp
freecodecamp.org › news › python-while-loop-tutorial-do-while-true-example-statement
Python While Loop Tutorial – Do While True Example Statement
August 24, 2020 - If you only have a single line of code within your while loop, you can use the single line syntax. ... If you are not careful while writing loops, you will create infinite loops. Infinite loops are the ones where the condition is always true.
🌐
Oregon State
web.engr.oregonstate.edu › ~webbky › ENGR102_files › Class_8_FLowchartWhileLoops.pdf pdf
ENGR 102 – Introduction to Engineering CLASS 8: FLOWCHARTS – WHILE LOOPS
Similar looking flowchart structures · for loop can be thought of as a special case of a while · loop · However, the distinction between the two is very · important · Webb · ENGR 102 · while Loop · 5 · Webb · ENGR 102 · 6 while Loop · Repeatedly execute an instruction or set of instructions · as long as (while) a certain condition is met (is true) Repeat A while X is true ·
Find elsewhere
🌐
Pythondex
pythondex.com › while-loop-flowchart-python
While Loop Flowchart In Python - Pythondex
December 25, 2016 - As you can see the first box in the flowchart inside that it is written · is condition true if the condition is false then as you can see the line arrow going to exit while loop which means the while loop will end.
🌐
Stack Overflow
stackoverflow.com › questions › 71352550 › flowchart-python
while loop - Flowchart - Python - Stack Overflow
counter = 0 while True: angka = input("Masukkan angka : ") if angka == '1': print("Biru") elif angka == '2': print("Merah") elif angka == '3': print("Hijau") else: print("Salah") counter += 1 if counter == 2: print("Anda telah memasukkan input ...
🌐
Datamentor
datamentor.io › python › while-statement
Python while Loop (With Examples)
The syntax of the while loop in Python is: while test_condition: statement(s) Here, the statements inside the while loop are executed for as long as test_condition is True. At first, test_condition is checked and if it is True then the body of the loop is entered. After one iteration, the test_condition is checked again. And this process continues until test_condition evaluates to False. Flowchart of Python while Loopo ·
🌐
Automate the Boring Stuff
automatetheboringstuff.com › 3e › chapter3.html
Chapter 3 - Loops, Automate the Boring Stuff with Python, 3rd Ed
Figure 3-2: The flowchart for the while statement code Description · In the while loop, the condition is always checked at the start of each iteration (that is, each time the loop is executed). If the condition is True, then the clause is executed, and afterward, the condition is checked again.
🌐
Medium
harshilbmk.medium.com › while-loops-in-python-day-11-931b2839cfc4
While Loops in Python — Day 11. Python While Loops | by Harshil Chovatiya | Medium
September 3, 2024 - A while loop repeatedly executes a block of code as long as a specified condition is true. The condition is evaluated before each iteration of the loop. If the condition is false, the loop is terminated.
🌐
Automate the Boring Stuff
automatetheboringstuff.com › 1e › chapter2
Chapter 2 – Flow Control
Figure 2-10. The flowchart for the while statement code · The code with the if statement checks the condition, and it prints Hello, world. only once if that condition is true. The code with the while loop, on the other hand, will print it five times.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-use-while-true-in-python
How to use while True in Python - GeeksforGeeks
May 27, 2025 - In Python, loops allow you to repeat code blocks. The while loop runs as long as a given condition is true. Using while True creates an infinite loop that runs endlessly until stopped by a break statement or an external interruption.
🌐
Creately
creately.com › home › examples › flowchart templates › while loop flow chart
While Loop Flow Chart | Creately
A while loop in flowcharts represents a control structure that repeatedly executes a block of code as long as a specified condition remains true. It is typically depicted using a diamond (decision) shape for the condition, followed by a loop connecting back to the process block if the condition ...
🌐
CodeRivers
coderivers.org › blog › python-flowchart
Python Flowcharts: A Comprehensive Guide - CodeRivers
May 17, 2018 - In the flowchart, the diamond would have the condition number % 2 == 0. The "true" arrow would lead to a rectangle with the text "Print 'The number is even'", and the "false" arrow would lead to a rectangle with "Print 'The number is odd'". For for and while loops in Python, the flowchart should ...
🌐
Problem Solving with Python
problemsolvingwithpython.com › 09-Loops › 09.04-Flowcharts-Describing-Loops
Flowcharts Describing Loops - Problem Solving with Python
A flowchart that describes this program is shown. The Python code that corresponds to this flow chart is: # start num = -1 while num < 0: num = input("Enter a positive number: ") num = float(num) print("positive") # end
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-while-loop
Python While Loop - GeeksforGeeks
When the condition becomes false, the line immediately after the loop in the program is executed. In this example, the condition for while will be True as long as the counter variable (count) is less than 3.
Published   December 23, 2025
🌐
Intellipaat
intellipaat.com › home › blog › python while loop
Python While Loop: Explained with While Loop Flowchart
October 14, 2025 - A Python while loop executes a code block repeatedly while a specified condition is true. This blog provides the complete flowchart of the while loop in Python.