[Tutor] bug in exam score conversion program
Dragos Ionescu
idragos at ymail.com
Sat Oct 4 19:18:01 CEST 2008
David try this:
score = input("What is your exam score: (0-100)? ")
print getGrade
print getGrade(score)
Regards,
Dragoshttp://scripts.mit.edu/~dionescu/pyworld/
----- Original Message ----
From: David <david at abbottdavid.com>
To: Brian C. Lane <bcl at brianlane.com>
Cc: tutor at python.org
Sent: Saturday, October 4, 2008 7:55:57 PM
Subject: Re: [Tutor] bug in exam score conversion program
When I run it from the idle it works perfect, but when I run it from a
file I get none, why is that?
>>> grades = [ (90,100,'A'),
(80, 89,'B'),
(70, 79,'C'),
(60, 69,'D'),
( 0, 59,'F'),
]
>>> score = 66
>>> 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]
>>> getGrade
<function getGrade at 0x84ec80>
>>> getGrade(score)
'D'
>>>
#!/usr/bin/python
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]
score = raw_input("What is your exam score: (0-100)? ")
print getGrade
print getGrade(score)
What is your exam score: (0-100)? 66
<function getGrade at 0x2b4b2a310d70>
None
--
Have Fun,
David A.
Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081004/15fe5ac0/attachment.htm>
More information about the Tutor
mailing list