Reputation: 277
Simple question but it is driving me nuts. why when I run this code does it just keep repeating itself? And my indentations are correct just had to space 4 times to post this for whatever reason.
High Scores
0 - Exit 1 - Show Scores
Source code:
scores = []
choice = None
while choice != "0":
print(
"""
High Scores
0 - Exit
1 - Show Scores
"""
)
choice = input("choice: ")
print()
if choice == "0":
print ("exiting")
elif choice == "1":
score = int(input("what score did you get?: "))
scores.append(score)
else:
print ("no")
input ("\n\nPress enter to exit")
Upvotes: 2
Views: 1216
Reputation: 1540
This is because you are not using proper indentation. Please indent the code under the while loop that you want to execute while choice != 0
Further there is no mistake with comparison as @wookie919 wrongly indicated because you're taking a String as input and not an Int. You can however typecast your input as a string by wrapping it around an int() like int(input("Choice .. "))
Hope it helped.
Upvotes: 1
Reputation: 3134
It's because you are comparing an Integer to a String. Try entering "0"
instead of just 0
. Or modify your program to compare with 0
instead of "0"
.
Upvotes: 0