TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Python Display the multiplication Table

Python Display the multiplication Table for beginners and professionals with programs on basics, controls, loops, functions, native data types etc.

<< Back to PYTHON

Python Program to Display the Multiplication Table

In Python, the user can write the program to display the multiplication table of any number. In this tutorial, we will discuss different methods for printing the multiplication table of any number using Python.

Method 1: Using For loop

In the following example, we will print the multiplication table of any number (from 1 to 10) by using the for loop.

Example:

number = int(input ("Enter the number of which the user wants to print the multiplication table: "))    
# We are using "for loop" to iterate the multiplication 10 times     
print ("The Multiplication Table of: ", number)  
for count in range(1, 11):    
   print (number, 'x', count, '=', number * count)  

Output:

Enter the number : 10
Enter the number of which the user wants to print the multiplication table:  13
The Multiplication Table of:  13
13 x 1 = 13
13 x 2 = 26
13 x 3 = 39
13 x 4 = 52
13 x 5 = 65
13 x 6 = 78
13 x 7 = 91
13 x 8 = 104
13 x 9 = 117
13 x 10 = 130

Explanation:

In the above program, we have taken an input integer number from the user. Then we have iterated for loop using the range (1, 11) function, which means greater than or equal to 1 and less than 11. In the first iteration, the loop will iterate and multiply by 1 to the given number. In the second iteration, 2 is multiplied by the given number, and so on.

In our case, we have printed the table of 10. You can provide the different numbers to test the program.

Method 2: By using While Loop

In this method, we will use the while loop for printing the multiplication table of any number specified by the user.

The following is the example for method 2:

Example:

number = int(input ("Enter the number of which the user wants to print the multiplication table: "))    
count = 1  
# we are using while loop for iterating the multiplication 10 times    
print ("The Multiplication Table of: ", number)  
while count <= 10:  
    number = number * 1  
    print (number, 'x', i, '=', number * count)  
    count += 1  

Output:

Enter the number of which the user wants to print the multiplication table:  27
The Multiplication Table of:  27
27 x 10 = 27
27 x 10 = 54
27 x 10 = 81
27 x 10 = 108
27 x 10 = 135
27 x 10 = 162
27 x 10 = 189
27 x 10 = 216
27 x 10 = 243
27 x 10 = 270

Explanation:

The above code is the same as the previous program, but we have used the while loop. We declared a variable "count" and initialized it by 1. The while loop will iterate until the value of "count" is smaller than and equal to 10. Each time loop is iterated, the value of "count" will be incremented by 1. When the "count" became greater than 10, the loop will be terminated.

Conclusion

In this tutorial, we have discussed two different methods which can be used for printing the multiplication table of any number using Python.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf