私はPythonで無限のwhileループ(ハイスコアビットを繰り返し表示し続ける)を作成することができましたが、それを修正するのに問題があります、何かアイデアはありますか?
ハイスコアビットの後にブレークインを追加すると、無限ループが停止しましたが、プログラムは、0を押さなくても、選択を代入すると、終了ボタンを押すようにユーザーに要求します。
#high scores
#demonstrates list methods
scores = []
choice = None
while choice != "0":
print(
"""
High Scores
0 - Exit
1 - Show Scores
2 - Add a Score
3 - Delete a Score
4 - Sort Scores
"""
)
choice = input("Choice: ")
print()
#exit
if choice == "0":
print("Goodbye")
#list high scores table
elif choice == "1":
print("High Scores")
for score in scores:
print(score)
#add a score
elif choice == "2":
score = int(input("What score did you get?: "))
scores.append(score)
#remove a score
elif choice == "3":
score = int(input("Remove which score?: "))
if score in scores:
scores.remove(score)
else:
print(score, "isn't in the high score list.")
#sort scores
elif choice == "4":
scores.sort(reverse=True)
#some unknown choice
else:
print("Sorry, but", choice, "isn't a valid choice.")
input("\nPress the enter key to exit.")
ありがとう。
print
インデントされているだけなので、残りの行はwhileブロックの一部ではありません
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加