[Tutor] bug in exam score conversion program

Alan Gauld alan.gauld at btinternet.com
Sun Oct 5 02:01:31 CEST 2008


"David" <david at abbottdavid.com> wrote

> When I run it from the idle it works perfect, but when I run it from 
> a
> file I get none, why is that?
>
>
>>>> score = 66

Here you directly assign a number to score

> #!/usr/bin/python
>
> score = raw_input("What is your exam score: (0-100)? ")

Here you assign a string - the result of raw_input

> print getGrade(score)

But getGrade expects to get an integer so yo need to
convert score to an int either when you pass it to getGrade
or, more usually, the return value from raw_input.

Passing a string to getGrade means it never finds a match
so never returns a grade and instead falls off the bottom with
no specified return value. When this happens Python inserts
a default return value of None

HTH,

Alan G 




More information about the Tutor mailing list