Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

if statement - Why is Python greater than operand not working?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...