[Tutor] My code isn't working properly
Sopan Shewale
sopan.shewale at gmail.com
Mon Jun 20 03:59:21 EDT 2016
You need to worry about indentation ;) & spells (.. you seriously want to
use input instead of raw_input? )
See if following works for you?
------
#!/usr/bin/python
scores = []
choice = None
while choice !="0":
print \
"""
High scores
0-Exit
1-Show scores
2-Add scores
3-Delete scores
4-Sort scores
"""
choice = raw_input("Choice: ")
print
if choice== "0":
print("Goodbye")
elif choice=="1":
print("High scores")
for score in scores:
print(score)
elif choice=="2":
score=int(raw_input("What score did you get?: "))
scores.append(score)
elif choice=="3":
score=int(raw_input("Remove which score?: "))
if score in scores:
scores.remove(score)
else:
print(score, "isnt in the high score list")
elif choice=="4":
scores.sort(reverse=True)
else:
print("Sorry but",choice,"isnt a valid choice")
raw_input("\nPress enter to exit")
-----------
Cheers,
--sopan shewale
On Mon, Jun 20, 2016 at 12:16 AM, Minhaj Ahmed via Tutor <tutor at python.org>
wrote:
> Hi,I'm studying Michael Dawsons 'Python programming for absolute
> beginners',in chapter 5,page 129,the author writes a program that records
> high scores in a game. I have done exactly as the author has set out and
> yet my code isn't doing what the author says it should be doing. The code
> is printed below.
>
> scores=[]
> choice=None
> while choice !="0":
> print(
> """
> High scores
> 0-Exit
> 1-Show scores
> 2-Add scores
> 3-Delete scores
> 4-Sort scores
> """
> )
> choice = input("Choice: ")
> print()
> if choice== "0":
> print("Goodbye")
>
>
> elif choice=="1":
> print("High scores")
> for score in scores:
> print(score)
>
>
> elif choice=="2":
> score=int(input("What score did you get?: "))
> scores.append(score)
>
> elif choice=="3":
> score=int(input("Remove which score?: "))
> if score in scores:
> scores.remove(score)
> else:
> print(score, "isnt in the high score list")
> elif choice=="4":
> scores.sort(reverse=True)
> else:
> print("Sorry but",choice,"isnt a valid choice")
>
> input("\nPress enter to exit")
>
> the only part of the program that seems to work is when i enter "0" to exit
> the program,any other number it just prints the beginning,which I know it
> should,but thats it. It doesn't ask for a new score when I enter "2" and
> even when I enter a supposedly invalid choice it still prints out the text
> in the while loop. Hope someone can help.
>
> Regards
>
> Minhaj
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list