Multiplication Table number margins
 Multiplication Table number margins CJ707 Unladen Swallow Posts: 3 Threads: 1 Joined: Sep 2019 Reputation: 0 Sep-18-2019, 04:25 AM Need to know how to format a 12*12 multiplication table to show a multiplication table chart with margins like this: X 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 The code to produce the table that fits in the margins above is below: ```def main(): rows = int(input("What is the upper bound of multiplication table? ")) print("The multiplication table for 2 to", rows) print() counter = 0 multiplicationTable(rows,counter) def multiplicationTable(rows,counter): size = rows + 1 for i in range(1,size): for nums in range (1,size): value = i*nums print(value,sep=' ',end="\t") counter += 1 if counter%rows == 0: print() else: counter main()``` Reply luoheng Silly Frenchman Posts: 29 Threads: 3 Joined: Sep 2018 Reputation: 11 Sep-18-2019, 07:21 AM What's the problem? The code works well. Here is an elegant way to show the table: ```def main(): rows = int(input("What is the upper bound of multiplication table? ")) print("The multiplication table for 2 to", rows) print() counter = 0 multiplicationTable(rows,counter) def multiplicationTable(rows,counter): size = rows + 1 for i in range(1,size): print(*(i*nums for nums in range(1, size)), sep='\t') main() ``` Reply CJ707 Unladen Swallow Posts: 3 Threads: 1 Joined: Sep 2019 Reputation: 0 Sep-18-2019, 01:51 PM Yes, but I'm needing to add one new row on top and a new column on the left of the table with an X in the upper left corner. X 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12 Reply luoheng Silly Frenchman Posts: 29 Threads: 3 Joined: Sep 2018 Reputation: 11 Sep-18-2019, 02:00 PM This code may help you. ```def main(): rows = int(input("What is the upper bound of multiplication table? ")) print("The multiplication table for 2 to", rows) print() counter = 0 multiplicationTable(rows,counter) def multiplicationTable(rows,counter): size = rows + 1 # header print("X", *range(1, size), sep='\t') for i in range(1,size): print(i, *(i*nums for nums in range(1, size)), sep='\t') main() ``` Reply CJ707 Unladen Swallow Posts: 3 Threads: 1 Joined: Sep 2019 Reputation: 0 Sep-18-2019, 02:16 PM Is there a way to do it using nested for loops? for i in range (1, 13): for j in range(1, 13): c = (i*j) Multi_table.append© Reply

 Possibly Related Threads… Thread Author Replies Views Last Post Creating table in MySQL db with decimal number issue dangermaus33 7 131 Nov-20-2020, 10:40 PM Last Post: dangermaus33 Fetch Oracle DB rows & print it in HTML file with table's col headers in table format tssr_2001 1 423 Sep-04-2020, 01:39 PM Last Post: ibreeden Mysql CREATE TABLE IF NOT EXISTS dynamic table name nisusavi 0 335 Apr-29-2020, 06:45 PM Last Post: nisusavi List conversion and multiplication johnkyp 5 757 Jan-02-2020, 08:20 AM Last Post: perfringo MYSQL how to assign a table for each user in my username table database? YoshikageKira 1 747 Dec-26-2019, 05:57 AM Last Post: buran Matrix Multiplication Issue VIJENDRA 1 385 Dec-19-2019, 06:16 PM Last Post: Gribouillis Multiplication between a list and a variable doug2019 2 469 Oct-08-2019, 04:10 AM Last Post: doug2019 multiplication by successive addition Zebrol 1 845 Sep-14-2019, 05:37 PM Last Post: ichabod801 Tracing a multiplication table w/ Python trace() NationalRex22 0 464 Jun-11-2019, 03:31 AM Last Post: NationalRex22 float multiplication - unexpected output inesk 3 994 Dec-11-2018, 10:59 AM Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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