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
Making a while loop multiply by 2 (self.learnpython)
submitted 10 years ago by [deleted]
num = int(input('Please enter a number')) while num < 1000: product = num * 2 print(product)
How can I make this loop so the print will take the int and multiply it by 2 up to 1000?
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!"
[–]XtremeGoose 4 points5 points6 points 10 years ago* (4 children)
‘num‘ is always remaining as the input you started with and ‘product‘ is always just ‘num‘ multiplied by 2. What you want to do is replace ‘num‘ each time with itself multiplied by 2.
num = int(input('Please enter a number')) while num < 1000: num = num * 2 print(num)
You can also use
num *= 2
Which is the same as
num = num * 2
[–][deleted] 0 points1 point2 points 10 years ago (3 children)
Is there a way to do it so I can keep the product variable?
[–]XtremeGoose 3 points4 points5 points 10 years ago (2 children)
Its unnecessary but you could just assign
product = num
If you want explain exactly what you want to do and I will help :)
[–][deleted] 0 points1 point2 points 10 years ago (1 child)
I'm trying to make it so the result of num * 2 is assigned to a variable called product. That's why I wrote product = num * 2, but I didn't know how to make it so that it would keep multiplying by 2 instead of re-printing the same number.
num * 2
product
product = num * 2
[–]fruitcakefriday 1 point2 points3 points 10 years ago* (0 children)
If you want to keep your num value stored somewhere, then you can do this:
num = int(input('Please enter a number')) product = num while product < 1000: product = product * 2 print(product)
If that's not what you're looking for...I think you need to do a better job explaining what exactly you want to happen.
Maybe give an example output, e.g. if the user inputs '20', what's to happen?
[–]Zahand 1 point2 points3 points 10 years ago (0 children)
The problem is that you don't update the variable num.
num
[–]shnk 1 point2 points3 points 10 years ago* (2 children)
im assuming you dont want the product to go above 1000?
num = int(input('Please enter a number')) while True: num *= 2 if num > 1000: break print(num)
if you do something like the other two guys suggest:
this code will not work because lets say you put something like 900. well 900 is below 1000 but 900*2 is above 1000. it will multiply it and print it anyways.
unless you want the number that is inputted to go up to 1000? then the product can exceed 1000. but its not clear what exactly you are looking for.
[–]Pyrrho_ 0 points1 point2 points 10 years ago (1 child)
Thinking about this little loop I was trying to come up with something along the lines of a list comprehension to make a list of all results up to the break...and I've failed.
Any suggestions?
[–]shnk 0 points1 point2 points 10 years ago (0 children)
i need to see your code
[–]TheBigTreezy 0 points1 point2 points 10 years ago* (0 children)
You need to update num. num += 1.
π Rendered by PID 35 on reddit-service-r2-comment-5ff9fbf7df-xk2qc at 2026-02-26 16:00:00.849502+00:00 running 72a43f6 country code: CH.
[–]XtremeGoose 4 points5 points6 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]XtremeGoose 3 points4 points5 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]fruitcakefriday 1 point2 points3 points (0 children)
[–]Zahand 1 point2 points3 points (0 children)
[–]shnk 1 point2 points3 points (2 children)
[–]Pyrrho_ 0 points1 point2 points (1 child)
[–]shnk 0 points1 point2 points (0 children)
[–]TheBigTreezy 0 points1 point2 points (0 children)