Python Forum

Full Version: creating a 3x3 multiplication table
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So im trying to get this as the output:
Output:
1 2 3 1| 1 2 3 2| 2 4 6 3| 3 6 9
Here's the code i'm using:
print('''   1  2  3''',end="")
for i in range(1,4):
	if i==1:
		print("")
	print('{:>1}|'.format(i),end="")
	for j in range(1,4):
		print('{:>2}'.format(i*j))
My issue is that after each loop in i runs, the output of i*jprints in the next line, so you get the output as:
Output:
1 2 3 1| 1 2 3 2| 2 4 6 3| 3 6 9
I'm new to python. please help
You are missing end="" in that line
print('{:>2}'.format(i*j))
BTW, for empty line, just use print()