[Tutor] bug in exam score conversion program

David david at abbottdavid.com
Sat Oct 4 18:55:57 CEST 2008


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



More information about the Tutor mailing list