Multiplication Table Using Recursion in Python

Multiplication Table Using Recursion in Python

Recursion is the most challenging part even for the senior developer today. Recursion means calling again and again. So, here we will write a function that will keep on itself until the condition is met i.e till the counter reaches 10.

In recursion, we don’t use loops like for loop or while loop. It’s the core logic that invokes the function until a condition. There is not a definite rule to write recursive functions. Hence you have to give a lot of focus while writing recursive functions in python.

Recursive function become an infinte loop even with a smallest mistake. Make sure to double check your code.

If you want to see all the practice examples and Explanations of Python then please use this reference to this URL. 

Also, See – complete Python Practice Series.

Print Multiplication Table Using Recursive Function

def rec_multiplication(num,count):
  if( count < 11):
     print(num," * ",count," = ",num * count)
     return rec_multiplication(num,count + 1)
  else:
    return 1

n = int(input("Enter any Number  :"));
rec_multiplication(n,1)

Output :

Enter any Number  :67
67  *  1  =  67
67  *  2  =  134
67  *  3  =  201
67  *  4  =  268
67  *  5  =  335
67  *  6  =  402
67  *  7  =  469
67  *  8  =  536
67  *  9  =  603
67  *  10  =  670

Look at the code above. You will see there are no loops. Just a condition inside a function. If the condition is true the function calls it itself. If you mess with the condition, you function will keep on running till infinity.

Conclusion and Summary

A multiplication table in python is an important example of python. It helps to solve the problem of printing complex multiplication tables of numbers that are not possible to remember like 167, 193, etc.

But the important reason behind learning this example is totally different. It helps you to understand the complex system of loops, functions, and recursion. Since multiplication table is something every student know, tutors can focus on programming concept.

The biggest catch for tutors and students is to find the examples that students understand at the functional level but not at the programming level. This helps to focus on the technicalities of programming very very easily.

Make sure you study maths very well if you want to become a great developer in the future.

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.