代码如下
def strToInt(s):
result =0
if(len(s) == 1):
return int(s)
else:
start = int(s[0:1])
result = (result+start)*10+strToInt(s[1:])
return result
print(strToInt('781'))
运行结果不如人意:151 ,应该是781呀
百思不得其解
代码如下
def strToInt(s):
result =0
if(len(s) == 1):
return int(s)
else:
start = int(s[0:1])
result = (result+start)*10+strToInt(s[1:])
return result
print(strToInt('781'))
运行结果不如人意:151 ,应该是781呀
百思不得其解
def change(s):
if len(s) == 1:
return int(s)
res = int(s[0]) * (10 ** (len(s)-1)) + change(s[1:])
return res
change('781')