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

pastebin.com/MyrLB704
Code: Select all
# High Scores
# Demonstrates list methods

scores = []

choice = None

while choice!= "0":

    print(
    """
High Scores

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

choice = input("Choice: ")
print()

# exit
if choice == "0":
    print("Good-bye.")

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

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

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

# sort scores
elif choice == "4":
    scores.sort(reverse=True)

# some unknown choice
else:
    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.
Adam335
 
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?
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 939
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 2 guests