When using the function in any of the python programs, architecture is the biggest challenge. Architect in the sense of what part should go in function. Ideally, the function should include the same type of code which is executed again and again. This way, we reduce the compiling time and increase the coding lines.
In the example of the Multiplication Table in Python, the multiplication operation will be performed again and again. So we will write the “function multiply” with two input parameters. And the return parameter will be the result, just like the below code.
Program to Print Multiplication Table Using Functions
def multiply(num,count): return num * count n = int(input("Enter any Number :")); i = 1 for i in range(1,11): print(n," * ",i," = ",multiply(n,i)) i = i + 1
Enter any Number :19 19 * 1 = 19 19 * 2 = 38 19 * 3 = 57 19 * 4 = 76 19 * 5 = 95 19 * 6 = 114 19 * 7 = 133 19 * 8 = 152 19 * 9 = 171 19 * 10 = 190
The above program is a simple program to print multiplication tables in Python using Functions. Here, the user enters the input of any number of his choice. Then we write the “function” which uses “i” as a counter variable. Then we used the range function, which directs the loop to start from 1 and run till less than 11, i.e. 10. Inside the loop, multiply “i” by “n” and store in the result in the variable value.
If you want to learn python programming, you can refer to this Python Online Course with Certification. It’s easy to understand and meant for beginners who have no background in programming.