這裏我想創建一個List(score []),我可以在其中添加,刪除,顯示和排序分數值。那麼排序時,我得到一個錯誤,這是代碼之後提到:實現列表並嘗試Python中的幾種方法
score=[];
choice=None;
while choice!=0:
print "1. Dislplay the score\n";
print "2. Add the score\n";
print "3. Delete a score\n";
print "4. Sort the scores\n";
choice=raw_input("enter the choice\n");
if choice=="1":
print score;
elif choice=="2":
print "enter the no. of scores u want to update";
add=int(raw_input("enter the scores u know:\n"));
i=0;
while i<add:
scores=int(raw_input("enter the score\n"));
score.append(scores);
i+=1;
elif choice=="3":
print "enter the score you want to delete or remove:\n";
del_score=int(raw_input("delete score:\n"));
if del_score in score:
score.remove(del_score);
else:
print "the required score is not found in the list";
elif choice=="4":
print "now its time to sort the scores in list\n";
sorted_score=score.sort();
sorted_sore=sorted_score.reverse();
print sorted_score;
else:
print "you have entered a wrong choice mate ";
的錯誤是 -
Error :Traceback (most recent call last):
File "C:\Users\Shijith\Desktop\python exer\listmethodsscore.py", line 29, in <module>
sorted_score=sorted_score.reverse();
AttributeError: 'NoneType' object has no attribute 'reverse'
網站注:在結束所有這些分號可省略。 –