,就把其中最大的一个打印出来。比如输入 137210,就打印 137;输入是27648923679就打印23679;输入是134127689就打印689;输入是1001,就打印1;如果输入的不是整数,就打印“not an integer”(用异常处理try...except);输入是123345,就打印345;输入是12738,就打印127(不是打印138,因为一定要连续的不能跳过数字)
如果输入是0134,就打印134,因为只能从大于0的数开始
限制:切片,for循环,列表解析式,lambda函数不能用
一定要用到while循环来做,不要用算法
def longestDigitRunSequence(n):
if n<0:
n-=n
count=1
prev=n%10
num=n%10
n=n/10
max=0
while n:
digit=n%10
if digit>=prev:
if count>max:
longest=num
max=count
elif count==max:
if num>longest:
longest=num
count=1
prev=digit
num=digit
else:
num=digit*10**count+num
prev=digit
count+=1
n=n/10
if count>max:
longest=num
max=count
elif count==max:
if num>longest:
longest=num
return longest
我这个代码在python3会有overflow error(错误),请问谁知道这题怎么写才对?