[Tutor] while loop
Dave Angel
davea at davea.name
Mon Mar 31 14:15:41 CEST 2014
Scott Dunning <swdunning at me.com> Wrote in message:
>
> On Mar 30, 2014, at 4:29 AM, Dave Angel <davea at davea.name> wrote:
>>
>> You're getting closer. Remember that the assignment shows your
>> function being called with 10, not zero. So you should have a
>> separate local variable, probably called I, which starts at
>> zero, and gets incremented each time.
>>
>> The test in the while should be comparing them.
>>
> So, this is what I have now and it ‘works’ but, instead of printing (s) on seperate lines they’re all on the same line?
>
> def print_n(s,n):
> while n < 10:
> print s * n
> break
> assert isinstance(s, str)
> assert isinstance(n, int)
>
>
So much for getting closer. Go back to the version I replied to.
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.
--
DaveA
More information about the Tutor
mailing list