Python Program To find Exponentiation

Sreemeenakshi V
1 min readJun 6, 2021

--

Python Function:

Function is a group of related statements that perform a specific task.

Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and manageable.

Furthermore, it avoids repetition and makes code reusable.

Syntax Of Function:

def function_name(parameters):"""docstring"""statement(s)

Problem Description:

The program takes a base and a power and finds the power of the base using recursion.

Take the base and exponential value from the user.

Pass the numbers as arguments to a recursive function to find the power of the number.

Give the base condition that if the exponential power is equals to 1, return the base number.

If the exponential power is not equal to 1, return the base number multiplied with the power function called recursively with the arguments as the base and power minus 1.

Print the final result.

Exit

If Statement:

if test expression:
statement(s)

Here, the program evaluates the test expression and will execute statement(s) only if the test expression is True.

If the test expression is False, the statement(s) is not executed.

Return Statement:

A return statement is used to end the execution of the function call and “returns” the result to the user. The statements after the return statements are not executed. If the return statement is without any expression, then the special value None is returned.

Script:

Output:

Enter base: 2Enter exponential value: 5Result: 32

For more Educational Assistance,

Refer: https://www.guvi.in/

--

--

No responses yet