[Tutor] while loop

Scott Dunning swdunning at me.com
Mon Mar 31 03:37:30 CEST 2014


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 exercise just asks to print (s), (n) times using iteration.  The exersise is in a doctest which I didn’t really understand at first.  So, I guess while I was doing it “correctly” it wasn’t what the exercise is asking for.  This I guess is what the doctest is looking for.

"""Print the string `s`, `n` times.

    Parameters
    ----------
        s -- A string
        n -- an integer, the number of times to
             print `s'

    Examples
    --------

    >>> print_n("hello", 3)
    hello
    hello
    hello

    >>> print_n("bye", 0)

    >>> print_n("a", 6)
    a
    a
    a
    a
    a
    a

    """
> 
> The test in the while should be comparing them.
> 
> Note that the number of times is specified in top level code, and
> implemented in the function.  You should not have a literal 10 in
> the function. 
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?  

SCott 










More information about the Tutor mailing list