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")
-
Are you sure you're running Python 3?Two-Bit Alchemist– Two-Bit Alchemist2016年07月27日 15:08:00 +00:00Commented Jul 27, 2016 at 15:08
-
sayan 98 is was my identation under my while loop. thank youJacob Moore– Jacob Moore2016年07月27日 22:14:48 +00:00Commented Jul 27, 2016 at 22:14
-
@JacobMoore happy to help!sayan– sayan2016年07月28日 07:35:05 +00:00Commented Jul 28, 2016 at 7:35
2 Answers 2
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.
Comments
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".