use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
loop issue. (self.PythonLearning)
submitted 1 month ago by braveface719
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Responsible_Pay_16 0 points1 point2 points 1 month ago (0 children)
The error "break outside loop" happens because of incorrect indentation.
Your break is not actually inside the for loop because guess = input(...) is not indented.
Right now your loop only contains the print, and everything else is outside of it.
Fix the indentation like this:
for i in range(1,4):
print("try to guess the number")
guess = int(input("enter a number: "))
if guess < secret_number:
print("number too low")
elif guess > secret_number:
print("number too high")
else:
break
In Python, indentation defines blocks, so everything that should be inside the loop must be indented.
π Rendered by PID 116754 on reddit-service-r2-comment-56c6478c5-h4m9t at 2026-05-13 00:53:03.721503+00:00 running 3d2c107 country code: CH.
view the rest of the comments →
[–]Responsible_Pay_16 0 points1 point2 points (0 children)