基本上我所要做的是獲取列表以不同的方式進行排序和顯示。但似乎在我做第一次打印後,它會得到「TypeError:'int'對象不可調用」。我假設這是因爲我在列表的末尾,需要在開始時重新啓動?不知道該怎麼做,或者如果這就是原因。Python - 如何排序通過我的列表
##vars
Index = 0
NumSize = 0
NumInput = 0
ManNum = 0
##Asking for list size
NumSize = int(input("How many numbers would you like to enter?:\n====>"))
##Declaring list
Numbers = [0] * NumSize
##Collecting data
for Index in range(NumSize):
NumInput = int(input("Please enter a number:\n====>"))
Numbers[Index] = NumInput
##Getting highest number
MaxNum = max(Numbers)
##Printing list
print("::::The numbers you entered were::::")
for Numbers in Numbers:
print(Numbers)
##Sorting list small to large
Numbers.sort()
print("::::The numbers while sorted::::")
for Numbers in Numbers:
print(Numbers)
##Sorting list large to small
Numbers.reverse()
print("::::The numbers reversed::::")
for Numbers in Numbers:
print(Numbers)
##Printing largest number
print("::::Largest number::::\n",
MaxNum)
你的代碼看起來像java,認真對待PEP8。 – simonzack 2014-11-09 07:51:28