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.- while True:
- print("\n============== Print Multiplication Table ==============\n")
- n=int(input("Enter the number to print the tables for: "))
- for i in range(1,11):
- print(n,"x",i,"=",n*i)
- opt = input("\nDo you want to try again?(yes/no): ")
- if opt.lower() == 'yes':
- ret=False
- elif opt.lower() == 'no':
- ret=True
- print("Exiting program....")
- else:
- print("Please enter yes/no:")
- break
- if ret == False:
- 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
Add new comment
- 14 views