0

If I take out the first if statement this code works fine. However, I need to set boundaries. I want to make it that the try only happens if the input is between 0 and 1. Can anyone please tell me where I'm going wrong?

try:  
    inp = raw_input ("Enter Score:")
    grade = float (inp)
    if 0 < grade < 1:        
        pass

    if grade >= 0.9: 
        print "A"

    elif grade >= 0.8:
        print "B"

    elif grade >= 0.7:
        print "C"

    elif grade >= 0.6:
        print "D"

    elif grade <= 0.6:
        print "F"

except: 
    print "please enter a value between 0 and 1"
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
evanito
  • 1
  • 1
  • `pass` is a no-op. It does nothing. The `if` statement may or may not match, but then nothing happens if it matches. You could use `if not (0 < grade < 1):` and then raise an exception. But there are better methods here, see the dupe. – Martijn Pieters Apr 27 '16 at 11:26
  • Thanks @MartijnPieters – evanito Apr 27 '16 at 11:51

0 Answers0