Python Multiplication Table of Number by Function Program
Working of Python Multiplication Table Program
First of all we define a user defined function print_table(num). Here num is a formal parameter which is a number to print its table.
print_table(num) function uses a for loop in the range 1 to 10 to display table of a number. Note that the range() function used in for loop uses two argumenst, start =1 and stop=11. It is because the range() function will generate numbers from start to stop-1. Therefore the range() function provides 1 to 10 numbers sequence to for loop. As a result, the multiplication table of the required number is printed from 1 to 10.
After the end of the function, we use an input() function to get input from the user. The user will enter a number. The int() function will convert the entered string into number.
The last statement is a function call statement.
We call the function print_table() by passing it the number.
Now the function print_table() is executed and prints the table.
And this is the end of the Python Multiplication table program using the user defined function print_table(num).
Please Enter a number to print its multiplication table:7 7 x 1 = 7 7 x 2 = 14 7 x 3 = 21 7 x 4 = 28 7 x 5 = 35 7 x 6 = 42 7 x 7 = 49 7 x 8 = 56 7 x 9 = 63 7 x 10 = 70
You may also like:
9,688 total views, 8 views today