Python program to find the multiplication of two numbers in table format

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.


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment