[Tutor] loops

Dave Angel davea at ieee.org
Tue Dec 8 11:39:59 CET 2009


Richard Hultgren wrote:
> a = 0
> b = 1
> count = 0
> max_count = 20
> while count < max_count:
>     count = count + 1
>     # we need to keep track of a since we change it
>     old_a = a                # especially here
>     old_b = b
>     a = old_b
>     b = old_a + old_b
>     # Notice that the , at the end of a print statement keeps it
>     # from switching to a new line
>     print old_a,
>
>
>
>       
>   
What's your question or comment?

If you're just looking for a challenge, I'll point out that the same 
result could be gotten with 4 lines of Python.

DaveA



More information about the Tutor mailing list