How to Print Multiplication Table in Python

In this tutorial, we will learn how to program "How to Print a Multiplication Table in Python." The objective is to print a multiplication table based on the user’s input. This tutorial will walk you through implementing this in Python using simple loops and basic arithmetic operations. You will learn how to generate a clean, formatted multiplication table for any given number and range. By the end of this tutorial, you will have a solid understanding of how to use loops to build structured output in Python.

This topic is straightforward to understand. Just follow the instructions I provide, and you will complete it with ease. The program I will demonstrate will show you the correct and efficient way to swap the first and last characters of a string. So, let’s dive into the coding process!

Getting Started:

First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.

Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.
  1. while True:
  2.     print("\n============== Print Multiplication Table ==============\n")
  3.  
  4.     n=int(input("Enter the number to print the tables for: "))
  5.     for i in range(1,11):
  6.         print(n,"x",i,"=",n*i)
  7.  
  8.  
  9.     opt = input("\nDo you want to try again?(yes/no): ")
  10.            
  11.     if opt.lower() == 'yes':
  12.         ret=False
  13.     elif opt.lower() == 'no':
  14.         ret=True
  15.         print("Exiting program....")
  16.     else:
  17.         print("Please enter yes/no:")
  18.         break
  19.  
  20.     if ret == False:
  21.         continue

This Python program prints the multiplication table of a user-specified number from 1 to 10. It prompts the user to enter a number, then iterates through values 1 to 10, multiplying each by the input number and displaying the result. After printing the table, it asks the user whether they want to try again. If the user enters "yes", the loop repeats; if "no", the program exits; any other input breaks the loop with a prompt.

Output:

There you have it we successfully created How to Print Multiplication Table in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials

Add new comment