0
Help me
Write a function power that accepts two arguments, a and b and calculates a raised to the power b. Example power(2, 3) => 8 Note: Don't use 2 ** 3 and don't use Math.pow(2, 3)
3 Answers
+ 4
# EDIT:
def power(x, y):
return x*power(x, y-1) if y!=0 else 1
print(power(4, 3))
>>>
64
+ 2
def power(a,b):
res=1
for i in range(b):
res*=a
return res
print(power(2,3))
0
#This code will accept the number and the power value from user to count its power
user_input=input("please enter a number and its power \n")
x=list(user_input )
count=1
power=int(x[1])
output=1
while count <=power:
output*=int(x[0])
count=count+1
print("your result is",output)