In: Computer Science
Write a python program. Grades are values between zero and 10 (both zero and 10 included), and are always rounded to the nearest half point. To translate grades to the American style, 8.5 to 10 become an “A,” 7.5 and 8 become a “B,” 6.5 and 7 become a “C,” 5.5 and 6 become a “D,” and other grades become an “F.” Implement this translation, whereby you ask the user for a grade, and then give the American translation. If the user enters a grade lower than zero or higher than 10, just give an error message. You do not need to handle the user entering grades that do not end in .0 or .5, though you may do that if you like – in that case, if the user enters such an illegal grade, give an appropriate error message.
#takes grade from user
grade = float(input("Enter a grade: "))
#checks if grade is less than 0 or greater than 10 then set ans to null
if(grade < 0 or grade > 10):
ans = ''
#checks if grade is less than 10 and greater than or equal to 8.5 then set ans to 'A'
elif(grade >= 8.5 and grade <= 10):
ans = 'A'
#checks if grade is less than 8 and greater than or equal to 7.5 then set ans to 'B'
elif(grade >= 7.5 and grade <= 8):
ans = 'B'
#checks if grade is less than 7 and greater than or equal to 6.5 then set ans to 'C'
elif(grade >= 6.5 and grade <= 7):
ans = 'C'
#checks if grade is less than 6 and greater than or equal to 5.5 then set ans to 'D'
elif(grade >= 5.5 and grade <= 6):
ans = 'D'
#checks if grade is less than 5.5 then set ans to 'D'
elif(grade < 5.5):
ans = 'F'
#checks if ans is not null then print the grade in american style otherwise print the error msg
if(ans!= ''):
print("Your grade in American style is: ",ans)
else:
print("Please enter valid grade")
OUTPUT: