[Tutor] while loop
Scott Dunning
swdunning at me.com
Sun Mar 30 03:36:43 CEST 2014
On Mar 29, 2014, at 12:47 AM, Dave Angel <davea at davea.name> wrote:
>
> So did your code print the string 10 times? When asking for help,
> it's useful to show what you tried, and what was expected, and
> what actually resulted.
>
> You use * to replicate the string, but that wasn't what the
> assignment asked for. So take out the *n part. You're supposed to
> use iteration, specifically the while loop.
>
> Your while loop doesn't quit after 10 times, it keeps going. Can
> you figure out why?
This works without a break. Is this more a long the line of what the excercise was looking for you think?
>
def print_n(s, n):
while n <= 10:
print s
n = n + 1
print_n("hello\n", 0)
More information about the Tutor
mailing list