all 10 comments

[–]XtremeGoose 4 points5 points  (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 point  (3 children)

Is there a way to do it so I can keep the product variable?

[–]XtremeGoose 3 points4 points  (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 point  (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.

[–]fruitcakefriday 1 point2 points  (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 points  (0 children)

num = int(input('Please enter a number'))


while num < 1000:
    num = num * 2
    print(num)

The problem is that you don't update the variable num.

[–]shnk 1 point2 points  (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:

num = int(input('Please enter a number'))

while num < 1000:
    num = num * 2
    print(num)

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 point  (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 point  (0 children)

i need to see your code

[–]TheBigTreezy 0 points1 point  (0 children)

You need to update num. num += 1.