In: Computer Science
by python
Question #1 Consider a 5-point quiz system. A score can be any number between 0 and 5. Using mathematical interval notation, the score is in the interval [0,5][0,5]. The interval notation (4,5](4,5] means that number 4 is not in the interval. Hence the numbers included in this interval are all real values ?x such that 4<?≤54
The score is graded according to the following scale:
Score | Grade |
---|---|
(4, 5] | A |
(3, 4] | B |
(2, 3] | C |
(1, 2] | D |
[0, 1] | F |
Write a program that reads a quiz score and then prints out the corresponding grade.
Note that your program should
The following are two sample runs of the program:
Sample Run 1:
Please enter score: -1
Invalid score. Try again.
Please enter score: 5.5
Invalid score. Try again.
Please enter score: 3.5
Your grade is B
#display grades according to your marks
def display_grade():
#takes input from the user
grade = input("Please enter score: ")
#1
if(4<grade<=5):
print("Your grade is A")
#2
elif(3<grade<=4):
print("Your grade is B")
#3
elif(2<grade<=3):
print("Your grade is C")
#4
elif(1<grade<=2):
print("Your grade is D")
#5
elif(0<=grade<=1):
print("Your grade is F")
#repeat the function when wrong input is given
#6
else:
print("Invalid score. Try again.")
display_grade()
return 0
dislpay_grade()
1. if gardes lie between 4 and 5 or equal to 5 then grade will be printed as "A".
2. if gardes lie between 3 and 4 or equal to 4 then grade will be printed as "B".
3. if gardes lie between 2 and 3 or equal to 3 then grade will be printed as "C".
4. if gardes lie between 1 and 2 or equal to 2 then grade will be printed as "D".
5. if gardes lie between 0 and 1 or equal to 0 and 1 then grade will be printed as "F".
6. if any other inputs is given then "Invalid" will be printed and the function repeat itselves.