There is no do-while loop in Python.
This is a similar construct, taken from the link above.
while True:
do_something()
if condition():
break
Answer from theycallmemorty on Stack OverflowThere is no do-while loop in Python.
This is a similar construct, taken from the link above.
while True:
do_something()
if condition():
break
I prefer to use a looping variable, as it tends to read a bit nicer than just "while 1:", and no ugly-looking break statement:
finished = False
while not finished:
... do something...
finished = evaluate_end_condition()
How to make a loop repeat until a condition is met. I want going left to be the condition that needs to be met.
Need help understanding this while loop
How do you loop until correct input is given?
Why not add do-while loops to Python?
Videos
print("You're in the lost forest\n" + "*" 25) print("" 25) print(" :-( ") print("" 25) print("" *25) print("Right or Left")
which_way = (str.capitalize(input ())) while which_way == "Right": print("HaHaHa!!! You are still in the forest!!!") break
I'm doing an assignment that requires I make a code that creates random numbers in a loop until I give a specific input. I just don't know how to get the loop to run while an input is requested. PLZ HELP!
EDIT:
To clarify the assignment:
Write a program that enters a number of positive integers.
The program ends when the user gives in a negative number.
a) Before the program ends, the largest number is printed.
b) Before the program ends, the smallest number is printed.
c) Before the program ends, the sum of the even numbers and the sum of the odd numbers are printed.
(I can do the a,b,c part no problem. It's the Program that creates the numbers i have problems with)
I asked my teacher what he meant by "a number of positive integers". He stated that the program should create numbers until the negative number is given.
EDIT 2:
I have concluded that I'm an idiot. It is the user who inputs the numbers. Thank you all for the help and not giving up with my dense skull :) (great community👍)