Multiplication Table in Python
Video Tutorial
Overview
While learning the for loop, while loop and other such python functions, one question that mostly strikes our mind is : What is the application of these python functions?
With the below article, we have the answer to your question. We shall explore the application of loops in python with elaborative examples, and we shall create multiplication tables of any number you need in python. Also, we will be exploring the different methods of doing the same, and each will give you enough insights that you become better at loops in python.
Let us dive straight into the module and understand it in more detail.
Scope
- This module will cover the application of loops in python by creating the multiplication tables in python with examples to give a better understanding of the source code.
- This module assumes the user of the manual to be well-versed with the fundamentals of python specifically - For loop, While loop, Input, Output and Import in python.
- This module is the perfect example of practising the loops in python and becoming better at it.
Print Multiplication Table in Python
In the module below, we shall dive deep into the source code to create a multiplication table in python. We can modify the source code and implement the multiplication table for any number. We will be discussing multiple methods for doing the same using python.
The examples we shall be looking forward are:
Using For loop
Let us understand by the below example how we can create multiplication tables in python using them for a loop.
Code:
Output: `
Explanation: Here we are making the use of for loop, helping us print the multiplication table of 4. We first ask the user to input the number for which we want the table to be printed, and then we iterate it ten times by range() function in for loop. The arguments we have provided inside the range() function are from (1, 11), which means that greater than or equal to 1 and less than 11 will be 10. We also have given the num as user input, but we can display it as any number if we don't want to ask the user for it.
Using While Loop
Let us understand by the below example how we can create multiplication tables in python using the while loop.
Code:
Output:
Explanation: Here we have used the while loop to print the multiplication table of 3 ( in our case). We know that while loop works until the condition specified by us holds true, which in our case is up till 10. So the while loop will work for ten times, and hence the multiplication table till ten times will get printed.
Conclusion
- We used concepts of for loop and while loop to print the multiplication table.
- You need to be well versed with For loop, While loop, Input, Output and Import in python. ::