2

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")
3
  • Are you sure you're running Python 3? Commented Jul 27, 2016 at 15:08
  • sayan 98 is was my identation under my while loop. thank you Commented Jul 27, 2016 at 22:14
  • @JacobMoore happy to help! Commented Jul 28, 2016 at 7:35

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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".

2 Comments

Where is OP comparing an int to a string?
@Two-BitAlchemist It's an educated guess after trying OP's code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.