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
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)))
for row in range(9,0,-1):
print(end="\t")
for column in range(9,0,-1):
print(row*column,end="\t ")
print()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With