[Tutor] while loop
Scott Dunning
swdunning at me.com
Tue Apr 1 01:22:13 CEST 2014
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
> n.
So like this?
def print_n(s,n):
i = 0
while i < n:
print s,
i += 1
print_n('a',3)
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?
Thanks for all of the help!
More information about the Tutor
mailing list