ITPub博客

首页 > 应用开发 > > 为什么输入四位数时,会出错

为什么输入四位数时,会出错

作者:johnchou 时间:2019-09-29 17:50:44 0 删除 编辑

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/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2020-11-13

  • 博文量
    80
  • 访问量
    7442