use*_*772 0 python string typeerror python-2.7
def power(num,div):
incre =0
while(num%div == 0):
num = num/div
incre +=1
return incre
test_case = int(raw_input())
lim = 0
while lim < test_case:
power = (raw_input())
x = power.split()
a = int(x[0])
b = int(x[1])
lim +=1
print power(a,b)
Run Code Online (Sandbox Code Playgroud)
Python曾经正常工作,直到我遇到此错误.
raw_input总是返回一个字符串对象.因此,这一行:
power = (raw_input())
Run Code Online (Sandbox Code Playgroud)
做power一个字符串.此外,当发生这种情况时,它会覆盖您的功能power.
当你到达这一点时:
print power(a,b)
Run Code Online (Sandbox Code Playgroud)
power 是一个字符串,你试图像调用函数一样调用它时会出错.
要解决此问题,请重命名函数或字符串.他们俩都无法命名power.
| 归档时间: |
|
| 查看次数: |
85 次 |
| 最近记录: |