Having troubles with being stuck in a infinite loop

This is the place for queries that don't fit in any of the other categories.

Having troubles with being stuck in a infinite loop

Postby Adam335 » Fri Aug 02, 2013 1:00 am

Code: Select all
# High Scores
# Demonstrates list methods

scores = []

choice = None

while choice!= "0":

High Scores

0 - Exit
1 - Show Scores
2 - Add a Score
3 - Delete a Score
4 - Sort Scores

choice = input("Choice: ")

# exit
if choice == "0":

# list high-score table
elif choice == "1":
    print("High Scores")
    for score in scores:

# add a score
elif choice == "2":
    score = int(input("What score did you get?: "))

# remove a score
elif choice == "3":
    score = int(input("Remove which score?: "))
    if score in scores:
        print(score, "isn't on the high scores list.")

# sort scores
elif choice == "4":

# some unknown choice
    print("Sorry, but", choice, "isn't a valid choice.")

input("\n\nPress the enter key to exit.")

I'm working on this program in my Python book, and for some reason it doesn't seem to be working.

I've read my code, it seems fine to me. Here's what the book says:

The High Scores program uses list methods to create and maintain a list of the user's best scores for a computer game. The program uses a simple, menu-driven interface. The user has a few choices. He or she can add a new score, delete a score, sort the scores, or quit the program.

When I run my code, it just keeps printing the same thing infinitely.

Any help?
Last edited by Yoriz on Fri Aug 02, 2013 5:38 am, edited 2 times in total.
Reason: Locked OP; added code to post, changed title.
Posts: 1
Joined: Fri Aug 02, 2013 12:55 am

Re: Having troubles with list methods in Python

Postby micseydel » Fri Aug 02, 2013 1:34 am

Is the indentation in your code the same as in your book?
Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Return to General Coding Help

Who is online

Users browsing this forum: Yahoo [Bot] and 14 guests