0

Make multiplication table columns on python 3

My code works properly as to show the multiplication. But instead vertically I want to have it displayed horizontally such as this: 1*1=1 2*1=2 and so on 1*2=2 2*2=4 . . . . 1*10=10 2*10=20 Here is the code I have: i=1 while i <= 10: b = 1 print('\nMultiplication with ' + str(i)) while b<=10: print("{} * {} = ".format(i, b), i*b,) b += 1 i += 1 Any guidance would be very appreciated. Edit: I'm sorry guys i don't think i phrased the question correctly. I know end="" would give me horizontal results but what i actually need is multiply by 1 to be one column where shown vertically. Multiply by 2 to be separate column next to it here is what i'm trying to do: Column 1 Column 2 Column 3 Multy 1 Multy 3 Multy 3 1*1=1 2*1=2 3*1=3 1*2=2 2*2=4 3*2=6 1*3=3 2*3=6 3*3=9 Is there a way for this to be done in Python 3?

21st Oct 2019, 2:25 AM
Aleksandar Mojsoski
Aleksandar Mojsoski - avatar
3 ответов
+ 7
Use end="" as the second parameter of the second print. Then add another empty print after the inner while loop.
21st Oct 2019, 3:32 AM
Sonic
Sonic - avatar
+ 2
Consider using "for" loops, it can shorten your codes. for i in range(1,11): for b in range(1,11): print("{} * {} = {}".format(b, i, i*b), end=" ") print() I leave it to you to make the spacing bewteen columns constant and to add the remaining text.
21st Oct 2019, 3:30 AM
Diego
Diego - avatar
+ 1
Here is another way to do this: Read the instructions in the comment at the top, it's important 👍 https://code.sololearn.com/cB9pwpjLNv4L/?ref=app
21st Oct 2019, 1:05 PM
~kyros~
~kyros~ - avatar