This program displays the multiplication table of numbers (from 1 to 12) using Python for loop and range function.
The Code:
columns = range(2,13) # from number 2 to 12 (index 13)
rows = range(2,13) # from number 2 to 12 (index 13)
for x in columns: # loop through the column range
print('\nTABLE ' + str(x))
for y in rows: # loop through the row range
product = x * y
print(str(x) + " x " + str(y) + " = " + str(product))
In this example, we have used the for loop along with the range() function to iterate tables 2 to 12 (and it can also be extended). The arguments inside the range() function (2, 12) can be modified to test for other values.
No comments:
Post a Comment