我需要一个函数,通过在for循环中使用乘法将数字提升到所述幂。这是我到目前为止所做的:
def power(num, power):
for x in range(power):
number = num * num
return number
print(power(3, 4))
答案 0 :(得分:1)
def power(base, exp):
res = 1
for _ in range(exp):
res *= base
return res
答案 1 :(得分:0)
应该是 -
def power(num,pow):
number = 1
for x in range(pow):
number=number*num
return number