[Tutor] loop problem

Sean 'Shaleh' Perry shalehperry@attbi.com
Mon, 10 Jun 2002 22:26:52 -0700 (PDT)


On 10-Jun-2002 Tinman wrote:
> I've been reading Alan's book on learning to program with Python. I'm 
> currently working with the chapter on loops. I have an idea for a loop 
> that I can't quite figure out. This is what I want to do.
> 
> 1.Multiply 1 by 2
> 2.Take the result and multiply by 2
> 3.So on and so on thirty times
> 4.Print the final result
> 
> I tried this:
> 
> for i in range(1,31):
>               b = i * 2
>               print b
> 
> This prints 1 -30 times 2 as I'm sure you can tell. I can't figure out 
> how to take each result an double it. Can anyone help a hapless Python 
> newbie?
> 

total = 2 # total starts at 1 * 2
for i in range(2,31): # start at 2
  total = total * 2
  print total

is this what you mean?