Trying to figure out how to add a loop to a program for class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Trying to figure out how to add a loop to a program for class

I've got some if/elif statements to determine what age group a person would fall into(you'll see in the code below) I need to make a loop that continues the "age evaluation" while the user wants to continue the loop I know how to setup while loops in general, but I'm struggling to add it into this specific code for whatever reason. https://code.sololearn.com/c4IwOD1paoUE/?ref=app

10th Feb 2019, 11:30 PM
Clay Allen
Clay Allen - avatar
7 Answers
+ 2
So it has to be the IDE ! :)
11th Feb 2019, 12:47 AM
Delorme
+ 1
Do you mean that the user has to make several inputs ? Then maybe you should ask the user for a list of ages as an input ?
10th Feb 2019, 11:46 PM
Delorme
+ 1
Diego Acero I've tried that and get an EOF Error... Seems to be complicated to ask for several inputs.
11th Feb 2019, 12:42 AM
Delorme
0
The user needs to input whether they'd like to continue the loop or not, and input the age in question, so yes multiple inputs.
10th Feb 2019, 11:48 PM
Clay Allen
Clay Allen - avatar
0
while True: # If user inputs 0 the program ends # You can choose any value if x == 0: break # Rest of the code goes here
11th Feb 2019, 12:24 AM
Diego
Diego - avatar
0
Delorme Try this as input (separate lines): 1 12 18 30 0 Or use and IDE that supports multiple inputs.
11th Feb 2019, 12:45 AM
Diego
Diego - avatar
0
Found a solution, I set a variable (in my case b) equal to one, started a while loop where the condition was b ==1, and prompt the user at the end to continue or not, if no b would be set to 0 to end the loop https://code.sololearn.com/c4IwOD1paoUE/?ref=app
13th Feb 2019, 4:39 AM
Clay Allen
Clay Allen - avatar