首页 > 应用开发 > > 为什么输入四位数时,会出错
list=[]
number=input("Please input end by #:")
whilenumber!='#':
list.append(number)
number=int(input("Please input end by #:"))
length=len(list)
fori inrange(0,length-1):
forj inrange(0,length-i-1):
iflist[j]>list[j+1]:
temp=list[j]
list[j]=list[j+1]
list[j+1]=temp
print(list)
测试:
Please input end by #:56
Please input end by #:8888
Please input end by #:#
Traceback (most recent call last):
File "D:/Python/workspace/Pybasis/Buble_sort.py", line 5, in <module>
number=int(input("Please input end by #:"))
ValueError: invalid literal for int() with base 10: '#'
Process finished with exit code 1
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4422/viewspace-3144413/ ,如需转载,请注明出处,否则将追究法律责任。