-5

I am working on a python lettering assignment.
90 or above is an A and so on and so on for the rest of the letter grades; but when a value is inputted as a negative number, I need the code to do nothing other than display an error.

This is what i tried so far:

#Design a Python program to assign grade to 10 students
#For each student, the program first asks for the user to enter a positive number
#A if the score is greater than or equal to 90
#B if the score is greater than or equal to 80 but less than 90
#C if the score is greater than or equal to 70 but less than 80
#D if the score is greater than or equal to 60 but less than 70
#F is the score is less than 60
#Ihen the program dispalys the letter grade for this student.
#Use while loop to repeat the above grade process for 10 students.

keep_going = 'y'

while keep_going == "y":

            num = float(input("Enter a number: "))
            if num >= 90:
                print("You have an A")
            elif num >= 80:
                print("You have an 3")
            elif num >= 70:
                print("You have an C")
            elif num >= 60:
                print("You have an D")
            elif (num < 60 and <= 0:
                print ("You have an F")

            else:
                print("lnvalid Test Score.")

Original screenshot

marcus erronius
  • 3,613
  • 1
  • 16
  • 32

3 Answers3

2

I see three problems, all in the same line:

elif (num < 60 and <= 0:
  1. Syntax: num < 60 and <= 0 is not a valid expression; should be num < 60 and num <= 0

  2. Logic: num <= 0 is not what you want, it should be num >= 0

  3. Syntax: you missed a closing bracket ).

If you change those, it should work.

Hugh Bothwell
  • 55,315
  • 8
  • 84
  • 99
0
grade = int(input("Enter Score:"))
print "FFFFFDCBAA"[grade//10] if grade >= 0 else "ERROR!!!!"
Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
0

you just have to change your elif for below 60.

keep_going = 'y'

while keep_going == "y":

        num = float(input("Enter a number: "))
        if num >= 90:
            print("You have an A")
        elif num >= 80:
            print("You have an 3")
        elif num >= 70:
            print("You have an C")
        elif num >= 60:
            print("You have an D")
        elif 60 > num >= 0:
            print ("You have an F")
        else:
            print("lnvalid Test Score.")
Seekheart
  • 1,135
  • 7
  • 8