Python Forum
creating a 3x3 multiplication table
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
creating a 3x3 multiplication table
#1
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
Reply
#2
You are missing end="" in that line
print('{:>2}'.format(i*j))
BTW, for empty line, just use print()
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a change table - £0.01-£0.50? MrKnd94 9 1,836 Oct-22-2022, 07:28 AM
Last Post: DPaul
  If statements and multiplication elroberto 1 1,658 Jun-22-2022, 05:35 PM
Last Post: deanhystad
  Find the maximum multiplication ercv 3 2,097 Nov-30-2020, 11:55 AM
Last Post: DeaD_EyE
  Multiplication Table Homework mcnhscc39 6 4,525 Nov-25-2018, 04:01 PM
Last Post: mcnhscc39
  Multiplication Table funnybone04 4 5,713 Apr-08-2018, 03:03 AM
Last Post: nilamo
  Nested Loop multiplication table SushiRolz 3 10,153 Feb-28-2018, 04:34 AM
Last Post: Larz60+
  Tricky estimating three models and creating a table: regression HellinPython 1 2,723 Oct-18-2017, 02:46 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020