+ 1
Can someone tell me the error in my program
number = ["fifty","hundred","thousand"] for x in number: print(x) if x == "hundred": break I'm getting a break outside loop error
3 Respuestas
+ 13
Check the INDENTATION of the if-statement
+ 6
The issue in your code is related to indentation. The break statement should be indented to be part of the loop block. Here's the corrected code:
number = ["fifty", "hundred", "thousand"]
for x in number:
print(x)
if x == "hundred":
break
+ 3
Nandita Gan Chaudhuri ,
It will probably be easier for you to catch your own indentation errors in the future if you make the indentations deeper so they are easier to see. The Python convention is four spaces per indentation level.
It will make it easier for others to read your code too, especially in the comments section, where spaces are narrower than in the editor.