Python Forum

Full Version: Help with a Code (Newbie)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello every one, im a newbie python programmer.I was just trying few codes the other day and came across a simple code, unfortunately its stuck in an infinite loop. I tried to figure it out but for no avail.It is basically a Score storing code which shows , adds , removes,sorts and exits based on users will. Down is the code im trying to run but the infinite loop problem arises.
-----------------------------------------------------------------------------------------------
scores = []

choice = None

while choice != 0:
    print("""
\t\t High Score

0 - Exit
1 - Show Scores
2 - Add scores
3 - Remove a Score
4 - Sort scores
""")

choice = input("Choice: ")

#Programe ends when user enters '0'
if choice == 0:
    print ('Good Bye')

#All the stored High scores are printed
elif choice == 1:
    print ('High Score')
    for score in scores:
        print (score)
        
#Lets user enter the High Score
elif choice == 2:
    score = int(input("What score did you get"))
    scores.append(score)
    
#Removes a Score
elif choice == 3:
    score = ("Remove which score?")
    if score in scores :
        score.remove(score)
        
else:
    print(score,'isnt in the score list')
-------------------------------------------------------------------------------------------
Oh and the indentations are proper, its just that when i post the thread, it automatically cancel out unwanted space.
input will return str, you need to convert it to int in order to compare with 1, 2, or 3
Or you need to compare user input with a str, i.e. '1', '2' or '3'