In: Computer Science
Programming
Python Jupiter notebook
Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table.
The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range, it asks him/her to enter a numeric input in the correct range, instead of returning an error.
Example:
Enter your score: 78
Letter grade: C
Enter your score: seventy
Please enter a numeric score
Python code:
#accepting mark
mark=input("Enter your score: ")
try:
#trying to convert it into integer
mark=int(mark)
#checking if mark is in the range
if(mark<0 or mark>100):
#asking to enter it in range
print("Please enter a numeric score in range 0-100")
#checking if grade is A
if(mark>=90 and mark<=100):
#printing A grade
print("Letter grade: A")
#checking if grade is B
elif(mark>=80 and mark<=90):
#printing B grade
print("Letter grade: B")
#checking if grade is C
elif(mark>=70 and mark<=80):
#printing C grade
print("Letter grade: C")
#checking if grade is D
elif(mark>=60 and mark<=70):
#printing D grade
print("Letter grade: D")
elif(mark>=0 and mark<=60):
#printing E grade
print("Letter grade: E")
except:
#asking to enter numeric score
print("Please enter a numeric score")
Screenshot:
Input and Output: