0
에 대한 무한 루프로 인해 타임 아웃을 해제하는 방법은 프로그램을 실행할 때마다 아래 표시된 메뉴를 실행하지만 사용자가 옵션을 선택해야하는 부분에 대해서는 다음과 같은 메시지가 표시됩니다. 다른 사용자가 제시 한 바와 같이 사용자가 옵션파이썬
from operator import itemgetter
high_scores = {"Benson ":100, "fizzlepop":300,"Mikey123":200}
def main():
choice = None
while choice != "0":
print(
"""
Hi scores system
0 - Quit
1 - Look up someone's high score
2 - Add a score
3 - Update a score
4 - Display all high-scores
"""
)
#After this point, the program begins to go into a time out as it seems to be going into an endless loop
choice = input("Choice: ")
#exit
if choice == "0":
print("Goodbye")
#look up a score
elif choice == "1":
player = input("Whose score would you like to look at?")
if player in high_scores:
score = high_scores[player]
print("\n", player, "'s score is ", score)
else:
print("Sorry, player ", player, "not in system")
elif choice == "2":
#Your answer to question 2 here-> this is where the user should be able to add a new name and score to the program
name= input("\nEnter new player name: ")
score= input("\nEnter score: ")
high_scores[name] = score
print("\n",name, "has been added")
#edit a high score
elif choice == "3":
#Your answer to question 3 here
print("Complete this part of the program")
#display all high scores
elif choice == "4":
for key, value in sorted(high_scores.items(), key=itemgetter(1), reverse = True):
print(key, value)
if __name__ == "__main__":
main()
PythonDictionaryScoreProgramIncomplete.py
혹시 파이썬 2에 오셨습니까? –
입력 뒤에'repr (choice)'를 사용하여'print'를 시도해 그 내용을 확인하십시오. –
어떤 OS입니까? 무슨 파이썬 버전? 어떻게 프로그램을 운영하고 있습니까? (나는 그 메시지가 파이썬 자체에서 오는 것으로 인식하지 못한다.) –