Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse Multiplication Table

I'm having troubling reversing my multiplication table.

This is what I have so far:

def reverseTable(n):
    for row in range(1, n+1):
        print(*("{:3}".format(row*col) for col in range(1, n+1)))

But I want to reverse it to:

25 20 15 10 5
20 16 12 8 4
15 12 9 6 3
10 8 6 4 2
like image 882
Ibrahim Sawaneh Avatar asked Jun 01 '26 13:06

Ibrahim Sawaneh


2 Answers

You need to reverse your range so it counts backwards. The range() function accepts 3 parameters, range(start, stop, step) so to count from 10 to 1 you would use range(10, 0, -1)

Try this:

def reverseTable(n):
    for row in range(n, 0, -1):
        print(*("{:3}".format(row*col) for col in range(n, 0, -1)))
like image 181
BrokenBinary Avatar answered Jun 04 '26 02:06

BrokenBinary


for row in range(9,0,-1):
    print(end="\t")
    for column in range(9,0,-1):
        print(row*column,end="\t ")
    print()
like image 36
Fikir Avatar answered Jun 04 '26 02:06

Fikir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!