- #1
mr.me
- 49
- 0
Hi everyone, I'm new to programming, studying python in school.
here's my first go at a loop to count up to 100 by 2, works fine
stop_count=100
count=2
while(count<=stop_count):
print count
count=count+2
But one of my practice problems is to use 'while' to
print 2 and all powers of 2 through and including 4096
I suppose I don't quite understand the math for a sequence of exponents or the correct syntax for the code, here's my try:
stop_pow=4096
base=2
while (base<=stop_pow):
print base
base= base**base+1
Which of course just printed the value of 2^3
Would someone please show me the correct code so I can understand my mistake and this type of operation.
here's my first go at a loop to count up to 100 by 2, works fine
stop_count=100
count=2
while(count<=stop_count):
print count
count=count+2
But one of my practice problems is to use 'while' to
print 2 and all powers of 2 through and including 4096
I suppose I don't quite understand the math for a sequence of exponents or the correct syntax for the code, here's my try:
stop_pow=4096
base=2
while (base<=stop_pow):
print base
base= base**base+1
Which of course just printed the value of 2^3
Would someone please show me the correct code so I can understand my mistake and this type of operation.
Last edited: