def strToint(strs):
def isNumber(c):
return c>="0" and c<="9"
if strs==None:
return strs
i=0
res=0
flag=False
if list(strs)[i]=="-":
flag=True
i+=1
if list(strs)[i]=="+":
i+=1
while i<len(strs):
if isNumber(list(strs)[i]):
res= res*10+ord(list(strs)[i])-ord('0')
else:
flag=False
print("不是数字")
return -1
i+=1
return -res if flag else res
网友评论