[Tutor] My code isn't working properly
Minhaj Ahmed
min786a at googlemail.com
Mon Jun 20 03:16:36 EDT 2016
Hi,I'm studying Michael Dawsons 'Python programming for absolute
beginners',in chapter 5,page 129,the author writes a program that records
high scores in a game. I have done exactly as the author has set out and
yet my code isn't doing what the author says it should be doing. The code
is printed below.
scores=[]
choice=None
while choice !="0":
print(
"""
High scores
0-Exit
1-Show scores
2-Add scores
3-Delete scores
4-Sort scores
"""
)
choice = input("Choice: ")
print()
if choice== "0":
print("Goodbye")
elif choice=="1":
print("High scores")
for score in scores:
print(score)
elif choice=="2":
score=int(input("What score did you get?: "))
scores.append(score)
elif choice=="3":
score=int(input("Remove which score?: "))
if score in scores:
scores.remove(score)
else:
print(score, "isnt in the high score list")
elif choice=="4":
scores.sort(reverse=True)
else:
print("Sorry but",choice,"isnt a valid choice")
input("\nPress enter to exit")
the only part of the program that seems to work is when i enter "0" to exit
the program,any other number it just prints the beginning,which I know it
should,but thats it. It doesn't ask for a new score when I enter "2" and
even when I enter a supposedly invalid choice it still prints out the text
in the while loop. Hope someone can help.
Regards
Minhaj
More information about the Tutor
mailing list