Power of a Number - Learn Engineering

All the news and updates relevant to Engineering. You can also Write a post here

Breaking

Friday, June 19, 2020

Power of a Number

python-mini

Question

To Find the power of a number.

Sample TestCaseExpected Output

Enter base :  2                                                                                                   Result : 8

Enter Exponential : 4

Answer


def power(base,exp):
    if(exp==1):
        return base
    if(exp!=1):
        return(base*power(base,exp-1))
base = int(input("Enter base : "))
exp = int(input("Enter exponential : "))
print("Result :",power(base,exp))

No comments:

Post a Comment