Support Our Site

To ensure we can continue delivering content and maintaining a free platform for all users, we kindly request that you disable your adblocker. Your contribution greatly supports our site's growth and development.

Python Program To Generate Multiplication table

2 min read

Problem Definition

Create a Python Program to generate the multiplication table of a number.

Program

num = int(input("Enter the Number :"))
for i in range(1,11):
    print("{} x {} = {}".format(num,i,num*i))

Output

Enter the Number :33 x 1 = 33 x 2 = 63 x 3 = 93 x 4 = 123 x 5 = 153 x 6 = 183 x 7 = 213 x 8 = 243 x 9 = 273 x 10 = 30

Explanation

First, we are taking input from the keyboard using the user using the input() method then later we are computing the table using a for loop in range of 1 to 11 then we are simply printing out the result using string formatting.

Alternatively, if you are using Python 3.6 or above you can take advantage of f-strings for string formatting.

Program

num = int(input("Enter the Number :"))
for i in range(1,11):
    print(f"{num} x {i} = {num*i}")

Output

Enter the Number :33 x 1 = 33 x 2 = 63 x 3 = 93 x 4 = 123 x 5 = 153 x 6 = 183 x 7 = 213 x 8 = 243 x 9 = 273 x 10 = 30

Using While Loop

num = int(input("Enter the Number :"))
i = 1while(i<=10):
    print("{} x {} = {}".format(num,i,num*i))
    i += 1

Output

Enter the Number :44 x 1 = 44 x 2 = 84 x 3 = 124 x 4 = 164 x 5 = 204 x 6 = 244 x 7 = 284 x 8 = 324 x 9 = 364 x 10 = 40

To learn more about While loops in Python reading the following articles is recommended.


PROGRAMS

Latest Articles

Latest from djangocentral

How to Use Subquery() in Django With Practical Examples

In the realm of web development, Django stands as a powerful and versatile framework for building robust applications. One of the key aspects of developing efficient and optimized web applications is handling database queries effectively. In this article…
Read more →

4 min read

DRF Serializer: Handling OrderedDict and Converting It to a Dictionary or JSON

In Django Rest Framework (DRF) tests, when you access serializer.data, you might encounter an OrderedDict instead of a regular dictionary. This behavior is intentional and reflects the design of DRF's serialization process.Understanding the Problem The u…
Read more →

3 min read

Django Rest Framework CheetSheet: Mastering API Development

Django Rest Framework (DRF) is a powerful toolkit that makes building robust and scalable web APIs with Django a breeze. Whether you're a seasoned Django developer or a newcomer, having a comprehensive cheat sheet at your disposal can be a game-changer. …
Read more →

5 min read

How to Perform NOT Queries in Django ORM

In Django, performing NOT queries allows you to exclude certain records from the query results based on specific conditions. The NOT operator, represented by the tilde (~) when used in conjunction with the Django ORM's Q object, helps you construct compl…
Read more →

3 min read