Python Power Function

Python power function example


#Python power function
# 3^3 is equal to 3x3x3 = 27


#example data
three = 3
power = 3

#Python power function create using recursion.
def power_function(number, power):
    if power == 0:
        return 1
    else:
        return number * power_function(number, power - 1)


print("{} to the power of {} is {}".format(three, power, power_function(three, power)))

#Python power function using pow method.
x = pow(three, three)

print(x)

------------------------------------------------------------------------------------
#Output
3 to the power of 3 is 27
27

Comments

Popular posts from this blog

How to write to a file in Kotlin

Python Tkinter example

Kotlin - Display Date picker dialog using EditText