HOW do you stop a print???

Fredrik Lundh fredrik at pythonware.com
Mon Nov 14 07:00:46 EST 2005


"john boy" <xray_alpha_charlie at yahoo.com> wrote:
> ok...I am running the following program:
>
> def printMultiples (n):
>      i = 1
>      while i <= 6:
>          print n*i,   ' \t ',
>          i = i + 1
> i = 1
> while i <= 6:
>      printMultiples(i)
>      i = i + 1
>
> this is supposed to return a simple multiplication table, but for
> some reason it does not want to stop printing after 6 columns...
> instead it prints from left to right for a total of 10 columns...
> I need some sort of a "stop print" after the first 6 columns

if "stop print" means "start a new line", a plain "print" will do
what you want:

    def printMultiples (n):
        i = 1
        while i <= 6:
            print n*i,   ' \t ',
            i = i + 1
        print

(you may also want to read up on the for-in loop statement;
the tutorial has more information on this)

</F>






More information about the Python-list mailing list