[Tutor] Newbie - Format question
Andy W
toodles@yifan.net
Thu, 6 Dec 2001 17:36:11 +0800
> >>>i = 1
> >>>while (i <= 3):
> j = 1
> while (j <= i):
> print i * j,
> j = j + 1
> i = i + 1
>
>
> 1 2 4 3 6 9
> >>>
>
> But I can't get inbetween. i,e.
> 1
> 2 4
> 3 6 9
Hi Barbara,
Try this:
i=1
while i<=3:
j=1
while j<=i:
print i*j,
j=j+1 #What version of Python are you using? If you're using 2.0 or
later you can use j+=1 to have the same effect.
print '' #This line is required to print a newline. Because you have the
comma at the end of "print i*j," it just keeps going...
i=i+1
HTH,
Andy