[Tutor] loops
spir
denis.spir at free.fr
Tue Dec 8 12:36:59 CET 2009
Lie Ryan <lie.1296 at gmail.com> dixit:
> On 12/8/2009 9:39 PM, Dave Angel wrote:
> > 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.
>
> you lose, 1 line is all it takes for me:
> print "0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181"
you lose, I don't even need a one-liner python prog to write a text into whatever stdout may be -- except if remote ;-)
Denis
________________________________
la vita e estrany
http://spir.wikidot.com/
More information about the Tutor
mailing list