How do I end this while true statement | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

How do I end this while true statement

while True: num = input('Enter age for all users separated by a comma: ') n = num.split(',') print(n) if len(n) >= 2: for i in range(len(n)): highest = max(n) lowest = min(n) print('Oldest person: ' + highest) print('youngest person: ' + lowest) else: print("Please, at least enter 2 numbers separated by ','")

9th Mar 2021, 5:09 PM
Ojukwu Franklin Ifeanyi
Ojukwu Franklin Ifeanyi - avatar
5 ответов
+ 1
add a break statement where you want to end it.
9th Mar 2021, 5:10 PM
Sharique Khan
Sharique Khan - avatar
+ 1
Show us the code from the code playground. Share the code link here and will edit it and solve the issue
9th Mar 2021, 5:14 PM
Sharique Khan
Sharique Khan - avatar
0
I did but dint work
9th Mar 2021, 5:11 PM
Ojukwu Franklin Ifeanyi
Ojukwu Franklin Ifeanyi - avatar
0
While True: i=0 while i<100: i = i+1 break Attention to identation!
9th Mar 2021, 6:51 PM
▲TopGun ▲
▲TopGun ▲ - avatar
0
when do you want to end loop? if you only want once iteration, you doesn't need the while line... if you know how many, you should use a counter to break when it reach 0 (initialized with number needed, decremented at each iteration) if you want to break on user specific input, you should add a test to verify if user want to end, then break also, if you use nested loop, you must break each nested loops between targeted loop to be broken and actual loop...
9th Mar 2021, 6:57 PM
visph
visph - avatar