Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

write a python program that prints a multiplication table for numbers 1…

Question

write a python program that prints a multiplication table for numbers 1 through 5 using nested loops. 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25

Explanation:

Step1: Outer loop for rows

We use a for loop to iterate from 1 to 5 for the rows of the multiplication table.

for i in range(1, 6):

Step2: Inner loop for columns

Inside the outer loop, we use another for loop to iterate from 1 to 5 for the columns of the multiplication table.

    for j in range(1, 6):

Step3: Print product and space

Inside the inner loop, we print the product of i and j followed by a space.

        print(i * j, end=' ')

Step4: Move to next line

After the inner loop finishes (i.e., after printing all elements in a row), we move to the next line.

    print()

Answer:

for i in range(1, 6):
    for j in range(1, 6):
        print(i * j, end=' ')
    print()