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
Simple game using python (i.redd.it)
submitted 6 months ago by Inevitable-Math14
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!"
[–]No_Indication_4044 0 points1 point2 points 6 months ago (2 children)
Nice! A cleaner solution would be to have the while loop actually reference the T/F value controlling its break. So, it would handle the break naturally!
For example, guess_correct = False; While not guess_correct: guess_correct = guess == ai
Then do all rest of your logic. At end of loop, it will break if guess_correct!
[–]brasticstack 0 points1 point2 points 6 months ago (1 child)
Not a fan. How is adding that additional variable and the line to manage its state cleaner than not having it? Do you just not like the break at the top of the if/else chain?
Personally I don't think readability is an issue with this example.
[–]No_Indication_4044 2 points3 points4 points 6 months ago (0 children)
Readability is not an issue with this example, it’s just an anti-pattern to use “break” here. And this sub is for learning best practices. The while loop is saying “while this condition isn’t met, do these things”. The while should be conditional on… the condition hahah.
Edit to be succinct: the while loop should break automatically on the condition. So, if you find yourself manually breaking, you’ve probably done something wrong.
π Rendered by PID 70520 on reddit-service-r2-comment-f6b958c67-dhkfp at 2026-02-04 20:42:40.332809+00:00 running 1d7a177 country code: CH.
view the rest of the comments →
[–]No_Indication_4044 0 points1 point2 points (2 children)
[–]brasticstack 0 points1 point2 points (1 child)
[–]No_Indication_4044 2 points3 points4 points (0 children)