0

Thank you for your help in advance.

I am a Jython beginner and I will gladly appreciate thorough help or explanations.

I have written a couple of lines in such manner...

for a1 in range(1,7):

for a2 in range(1,2):

A=a1*a2

print A, 

for b1 in range(1,7):

for b2 in range(1,2):

B=b1*b2*2

print B,

The result in the output is such: 1 2 3 4 5 6 2 4 6 8 10 12

I would like to separate the two in such manner:

1 2 3 4 5 6

2 4 6 8 10 12

Using the "\n" command. How is it possible to do? What would be the best way to do this?

1 Answers1

2

A simple print after each loop will do the trick...

for a1 in range(1,7):
    for a2 in range(1,2):
        A=a1*a2
        print A, 
print 
for b1 in range(1,7):
    for b2 in range(1,2):
        B=b1*b2*2
        print B,
print 

Actually printing a "\n" (i.e. print "\n") would also leave a blank line between the two output lines, although I suppose you could do ...

print "\n",

See also the question What's ending comma in print function for? for more details.

Community
  • 1
  • 1
Jeremy Gosling
  • 1,130
  • 10
  • 11