Hello everyone, welcome to nkcoderz.com. In this article we will going to discuss about Python program to find the multiplication of two numbers in table format.
Here’s a Python program that will display the multiplication table of two numbers in a table format:
Code for python program to find the multiplication of two numbers in table format
def mult_table(n, m):
# Print the header of the table
print(" " * 5, end="") # 5 spaces
for i in range(n, n+1):
print(f"{i:5}", end="")
print() # New line
# Print the rows of the table
for i in range(1, m+1):
print(f"{i:5}", end="") # Row number
for j in range(n, n+1):
print(f"{i*j:5}", end="") # Cell value
print() # New line
# Test the function
mult_table(5, 10)
This program will print out the multiplication table for the numbers 5 and 10. The output will look like this:
Output
5
1 5
2 10
3 15
4 20
5 25
6 30
7 35
8 40
9 45
10 50
You can modify the program to display the multiplication table for any other numbers by changing the values of n
and m
in the mult_table
function.
Python program to find Celsius to Fahrenheit and its reverse using if statement
Conclusion
If you liked this post, then please share this with your friends and make sure to bookmark this website for more awesome content.