Hi, can anyone can tell me why this program that I am trying to use it is telling me "break outside the loop" | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

Hi, can anyone can tell me why this program that I am trying to use it is telling me "break outside the loop"

I'm trying to do a test task and I'm trying to use this code : a=[] while True: num=input() if num>="0": a.appen(num) else: break print(a) But when I'm trying to use it it tell' s me" break is outside the loop" i don't know if it is a problem with the code it self or is something that I'm doing wrong. If anyone can help me I'll appreciate it

4th Mar 2021, 8:32 PM
Alan Restrepo
Alan Restrepo - avatar
5 Antworten
+ 1
Try the following: ————————————————————— a = [] while True: num=input() if num != "0": a.append(num) else: break print(a) ————————————————————— EDIT SUMMARY: • set indentation inside of while loop to be 5 spaces (1 tab) in • added a “d” to appen • changed “>= “ (less than or equal to) to “!=“ (is not) ————————————————————— I think you accidentally used a >= symbol on “0” this doesnt work since it is a string and not a number.
4th Mar 2021, 11:32 PM
Ethan
Ethan - avatar
0
Because of indentation!!! that else is not referred to the if inside the while loop, but to the while loop itself
4th Mar 2021, 8:34 PM
Angelo
Angelo - avatar
0
Ok , so I should take away the else right? Because the test task that I'm trying to do tell s me that if the input is equal to 0 , the loop have to end
4th Mar 2021, 8:41 PM
Alan Restrepo
Alan Restrepo - avatar
0
The problem is that i don't know how to make work i been trying but I don't know the right way
4th Mar 2021, 8:53 PM
Alan Restrepo
Alan Restrepo - avatar
0
If you fix the indentaton an run the program in SoloLearns app, you will still have problem with EOFError, that you have to catch, according to the input function call inside the loop. Catch the error or run the program in for example Python IDLE.
4th Mar 2021, 9:04 PM
Per Bratthammar
Per Bratthammar - avatar