[Tutor] Newbie - Format question

Kirby Urner urnerk@qwest.net
Thu, 06 Dec 2001 07:56:55 -0800


>
>But I can't get inbetween. i,e.
>1
>2 4
>3 6 9

Hi Barbara --

A couple more solutions, just for fun:

  >>> def sequences(max):
         for b in range(1,max+1):
             for a in range(1,b+1):
                 print a*b,
             print


  >>> sequences(5)
  1
  2 4
  3 6 9
  4 8 12 16
  5 10 15 20 25

  >>> def sequences(max):
          for b in range(1,max+1):
             print ' '.join([str(a*b) for a in range(1,b+1)])

  >>> sequences(5)
  1
  2 4
  3 6 9
  4 8 12 16
  5 10 15 20 25

Kirby