Q:

Enter a number N, and then the program proceeds to output all powers of two smaller than N. How could I continue?

So right now I have this:
number = int(input("Enter a number: "))
exponent = 0

while exponent <= number:
    result = 2 ** exponent  
    exponent = exponent + 1
    print(result)

For example:
If I input 21 it prints out all 21 numbers, but I need the program to print out the numbers that are less than 21 like so:
1
2
4
8
16

But not all of 21 numbers.

A:

Use this loop instead:
while 2 ** exponent <= number:
    print(2 ** exponent) 
    exponent = exponent + 1

