Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Python function MultiplicationTable() which takes a positive int value n

ID: 3778719 • Letter: W

Question

Write a Python function MultiplicationTable() which takes a positive int value n and produce n by n multiplication table on the screen. The function does not return any value. (See the sample output in the starter code.) Numbers must be right justified with column width 5. For this requirement, you must use string formatting covered in the book. MultiplicationTable starter code: def MultiplicationTable(n): # Your code goes here def test_mt(): for i in range(5, 15, 5): MultiplicationTable(i) print() test_mt() You can use for loops or while loops for this problem. Do not modify the tes_rt() function.

Explanation / Answer

def MultiplicationTable(n):
    for i in range(1,n+1):
        #Right justified by column width 5.
        s1 = str(n).rjust(5,' ')
        s2 = str(i).rjust(5,' ')
        s3 = str(n*i).rjust(5,' ')
        # print table
        print("%s X %s = %s " % (s1,s2,s3))
def test_mt():
    for i in range(5,15,5):
        MultiplicationTable(i)
        print()
test_mt()

"""
sample output

    5 X     1 =     5

    5 X     2 =    10

    5 X     3 =    15

    5 X     4 =    20

    5 X     5 =    25


   10 X     1 =    10

   10 X     2 =    20

   10 X     3 =    30

   10 X     4 =    40

   10 X     5 =    50

   10 X     6 =    60

   10 X     7 =    70

   10 X     8 =    80

   10 X     9 =    90

   10 X    10 =   100
"""

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote