[Tutor] Question about comparing values
Becky Mcquilling
ladymcse2000 at gmail.com
Sun May 22 23:11:56 CEST 2011
I realize this is a fairly generic type of question, but being new to
programming, I'm not sure how best to approach it.
I'm doing a tutorial and was given a problem, using shelve. It's taking a
user name and then asking for scores in a game, until you end the loop.
Whatever score is the high score, should be returned from the function:
Here is what I have so far:
import shelve
def user_scores():
user_name = input ("What is the user name?").rstrip()
scores = int(input("What is the users score, enter 0 if done"))
shelf = shelve.open('scores.py', writeback=True)
score = [scores]
user = {user_name:score}
shelf['user'] = user
shelf.close()
while scores > 0:
scores = int (input("What is the next score"))
shelf = shelve.open('scores.py', writeback=True)
score.append(scores)
shelf['score'] = score
shelf.sync()
shelf.close()
What I'm not sure of is how to compare the values of score, to find and
print the one that is highest. Any suggestions?
Becky
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110522/0be54f25/attachment.html>
More information about the Tutor
mailing list