0

I am creating code for a simple teachers grading system in which you input the numeric grade and it tells you if it is an A, B, C, etc. I first wanted to put a limit on the numbers you can input, i.e. can't put less than zero or more than one hundred, but it is not working. Can anyone explain why?

import time
from time import sleep
grade = 0
maximum = 100
minimum = 0
grade = input("""Insert numeric grade:
""")
time.sleep(1)
if grade > maximum:
    print ("Please enter a valid grade.")

1 Answers1

0

Basically you should fix this line:

if int(grade) > maximum:

because the result of input is a string, not a number, so the wrong comparison is used.

Of course, you could (and should!) also properly check that user has entered an integer value, otherwise there will be a ValueError.

try:
   if int(grade) > maximum:
      print("enter a value less than maximum")
except ValueError:
   print("enter an integer value")
Pac0
  • 21,465
  • 8
  • 65
  • 74