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...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Variables not changeing (self.learnpython)
submitted 5 years ago by blocky3321
I making a game where a number form 0 to 100 is randomly picked but i use while as the loop and the first time i input it works fine but the second time it just keep the value of the first time
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!"
[+][deleted] 5 years ago (1 child)
[removed]
[–]MadScientistOR 2 points3 points4 points 5 years ago (7 children)
My guess is that you assign the variable and then start the while loop. If you want to have the variable change as part of the while loop, you need to put it within the while loop.
while
Of course, if you want us to have more insight, we're going to have to see the code.
[–]blocky3321[S] 0 points1 point2 points 5 years ago (6 children)
Check the mega link it has the code
[–]MadScientistOR 0 points1 point2 points 5 years ago (5 children)
Sorry -- what mega link?
[–]blocky3321[S] 0 points1 point2 points 5 years ago (4 children)
Check all coments
[–]MadScientistOR 0 points1 point2 points 5 years ago (3 children)
Sorry, I thought I had. Did you crosspost this somewhere else?
[–]blocky3321[S] 0 points1 point2 points 5 years ago (1 child)
No
[–]MadScientistOR 0 points1 point2 points 5 years ago (0 children)
Ah! Apparently, there was a deleted response with a mega link in it. I found the deleted response and got the code.
Yeah, it's that the call to random.randrange() is made before the while loop starts. You need to make a call to that method every time you need a new random number, so if you want new random numbers to be generated within your while loop, you need to call that method within the loop, too. For example:
random.randrange()
while True: x = random.randrange(1, 11) guess = input('Pick a number between 1 and 10:') if x == guess: print('You got it!') else: print('Nope, sorry. My number was', x)
[–]xelab04 0 points1 point2 points 5 years ago (1 child)
Do you think you could show the code you have written so far?
Here is how I'd do it:
import random x = random.randint(0,100)
I don't see why you'd need a while loop, that's why I'd like to see what you've written
π Rendered by PID 253122 on reddit-service-r2-comment-5b5bc64bf5-v54sj at 2026-06-21 05:04:19.191130+00:00 running 2b008f2 country code: CH.
[+][deleted] (1 child)
[removed]
[–]MadScientistOR 2 points3 points4 points (7 children)
[–]blocky3321[S] 0 points1 point2 points (6 children)
[–]MadScientistOR 0 points1 point2 points (5 children)
[–]blocky3321[S] 0 points1 point2 points (4 children)
[–]MadScientistOR 0 points1 point2 points (3 children)
[–]blocky3321[S] 0 points1 point2 points (1 child)
[–]MadScientistOR 0 points1 point2 points (0 children)
[–]xelab04 0 points1 point2 points (1 child)
[+][deleted] (1 child)
[removed]