[Tutor] Question about comparing values

Hugo Arts hugo.yoshi at gmail.com
Sun May 22 23:21:53 CEST 2011


On Sun, May 22, 2011 at 11:11 PM, Becky Mcquilling
<ladymcse2000 at gmail.com> wrote:
> 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
>
>

Look up the function called max(). I think that should take care of
what you need.

Hugo


More information about the Tutor mailing list