A certain CS professor gives five-point quizzes that are graded on the scale:
5→A4→B3→C2→D1→E0→E5→A4→B3→C2→D1→E0→E
Complete a program that accepts a quiz score as an input, and uses decision structures to calculate the corresponding grade. Do this by implementing the functions, below:
num_to_letter(num)
Given a numerical grade between 0 and 5, return the appropriate letter grade.
main()
Write a main() asks the user for a numerical score between 0 and 5, and prints out the letter grade. You must use your num_to_letter function as defined above.
Tip 1: Fractional scores are allowed, e.g. a score of "4.5" is a "B" grade, or "1.7" is an "E". So make appropriate comparisons in your conditions.*
Tip 2: Scores could possibly be less than 0, or greater than 5. Just assign it an ‘E’, or ‘A’ respectively.
Output
For example, if the score of 5 is entered, a letter grade of "A" is returned.
Enter a numerical score (0-5): 5
Grade is A

Respuesta :

Answer:

In Python:

def num_to_letter(num):

   if num == 5:

       grade = "A"

   elif num >= 4.0:

       grade = "B"

   elif num >= 3.0:

       grade = "C"

   elif num >= 2.0:

       grade = "D"

   else:

       grade = "E"

   return "Grade is "+grade

Explanation:

This defines the function

def num_to_letter(num):

If num is 5, grade is A

   if num == 5:

       grade = "A"

If num is 4 to 4.9 , grade is B

   elif num >= 4.0:

       grade = "B"

If num is 3 to 3.9, grade is C

   elif num >= 3.0:

       grade = "C"

If num is 2 to 2.9, grade is D

   elif num >= 2.0:

       grade = "D"

For 0 to 1.9, grade is E

   else:

       grade = "E"

This returns the grade

   return "Grade is "+grade