Simple integer comparison problem

Jakub Stolarski jakub.stolarski at gmail.com
Sat Apr 14 11:26:26 EDT 2007


On Apr 14, 5:19 pm, t... at finland.com wrote:
> Hi!
> I ran in problem with simple exercise. I'm trying to get program to
> return grade when given points but no matter what, I always get F.
>
> def grader():
>      print "Insert points: "
>      points = raw_input('> ')
>      int(points)
>
>      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"
>
> grade = grader()
> print grade

You should write:
points = int(points)

int returns value, not change in place.

If I can suggest you can use simpler if-statement:
if 89 < points <= 100:




More information about the Python-list mailing list