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)

4th Jul 2017, 4:37 PM
olusola olatunde
olusola olatunde - avatar
3 Answers
+ 4
# EDIT: def power(x, y): return x*power(x, y-1) if y!=0 else 1 print(power(4, 3)) >>> 64
4th Jul 2017, 6:48 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 2
def power(a,b): res=1 for i in range(b): res*=a return res print(power(2,3))
4th Jul 2017, 4:41 PM
Sandesh
Sandesh - avatar
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)
5th Jul 2017, 10:56 PM
Mohamed Raouf
Mohamed Raouf - avatar