[Tutor] while loop

David Rock david at graniteweb.com
Mon Mar 31 15:45:32 CEST 2014


* Scott Dunning <swdunning at me.com> [2014-03-30 18:37]:
> Without out a break or placing that 10 in there I can’t think of a way
> to have the while loop stop once it reaches (n).  Any hints?  

As discussed already, you can't use fixed values (ie, you don't know
that 10 is always going to be there).

> def print_n(s, n):                                                                                                             
>     while n <= 10:                                                                                                             
>         print s                                                                                                                
>         n = n + 1                                                                                                              
>                          

So, instead of 

    while n <= 10:                                                                                                             

Think about:

    while something <= n:

and changing something and retesting.

-- 
David Rock
david at graniteweb.com


More information about the Tutor mailing list