"Brian C. Lane" <[EMAIL PROTECTED]> wrote

# min, max, grade
grades = [  (90,100,'A'),
           (80, 89,'B'),
           (70, 79,'C'),
           (60, 69,'D'),
           ( 0, 59,'F'),
       ]

def getGrade(score):
   """
   Return a letter grade based on a score
   """
   for g in grades:
       if (score <= g[1]) and (score >= g[0]):
           return g[2]

Could be written more concisely as

for g in grades:
   if g[0] <= score <= g[1]:
       return g[2]




--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld









- --
- ---[Office 71.6F]--[Outside 55.4F]--[Server 107.9F]--[Coaster 71.7F]--- - ---[ WSF KITSAP (366772980) @ 47 34.7811 -122 4 ]--- Software, Linux, Microcontrollers http://www.brianlane.com AIS Parser SDK http://www.aisparser.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Remember Lexington Green!

iD8DBQFI535RIftj/pcSws0RAldqAJ9yKYSyDArc/LZ6G47SwxUq4z8yAACgioyx
b9WnwDEQe8hSOuYbKuKo9sY=
=7lCV
-----END PGP SIGNATURE-----
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to