list=[] number=input("Please input end by #:") while number!='#': list.append(number) number=int(input("Please input end by #:")) length=len(list) for i in range(0,length-1): for j in range(0,length-i-1): if list[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
MAYA_MUYI
相关分类