Simple integer comparison problem
Bart Willems
b.r.willems at gmail.com
Sat Apr 14 12:46:15 EDT 2007
> if points > 89 and points <= 100:
> return "A"
> elif points > 89 and points <= 89:
> return "B"
> elif points > 69 and points <= 79:
> return "C"
> elif points > 59 and points <= 69:
> return "D"
> else:
> return "F"
The previous posters already pointed out your int problem. However, the
if-statement can be written with a lot less clutter:
if points > 100:
return "Illegal score"
elif points > 89:
return "A"
elif points > 79:
return "B"
elif points > 69:
return "C"
elif points > 59:
return "D"
else:
return "F"
I have a feeling that there's a Python-solution that is shorter yet
better readable, I just can't figure it out yet...
More information about the Python-list
mailing list