[Tutor] while loop
davea at davea.name
Tue Apr 1 11:58:42 CEST 2014
Scott Dunning <swdunning at me.com> Wrote in message:
> On Mar 31, 2014, at 5:15 AM, Dave Angel <davea at davea.name> wrote:
>> Do you know how to define and initialize a second local variable?
>> Create one called i, with a value zero.
>> You test expression will not have a literal, but compare the two
>> locals. And the statement that increments will change i, not
> So like this?
> def print_n(s,n):
> i = 0
> while i < n:
> print s,
> i += 1
> So this is basically making i bigger by +1 every time the while loop passes until it passes n, then it becomes false right?
> Also, with this exercise itâs using a doctest so I donât actually call the function so I canât figure out a way to make the stringâs print on separate lines without changing the doctest code?
The trailing comma on the print statement is suppressing the
newline that's printed by default. If you want them on separate
lines, get rid of the comma.
More information about the Tutor