(Convert letter grade to number) Write a program that prompts the user to enter a letter grade A/a, B/b, C/c, D/d, or F/f and displays its corresponding numeric value 4, 3, 2, 1, or 0.

Sample Run 1 Enter a letter grade: B The numeric value for grade B is 3

Sample Run 2 Enter a letter grade: b The numeric value for grade b is 3

Sample Run 3 Enter a letter grade: T T is an invalid grade

Respuesta :

Answer:

This program is written in Python Programming Language

Program doesn't make use of comments (See Explanation Section for detailed explanation)

letterg = ['A','B','C','D','F']

inp = input("Enter a Letter Grade: ")

for i in range(len(letterg)):

if inp.upper() == letterg[i]:

print('The numeric value for grade ', inp, ' is ',4 - i)

break;

else:

print(inp, "is an invalid grade")

Explanation:

This line initializes all letter grade from A to F

letterg = ['A','B','C','D','F']

This line prompts user for letter grade

inp = input("Enter a Letter Grade: ")

This line iterates through the initialized letter grades

for i in range(len(letterg)):

This line checks if the user input is present in the initialized letter grades (it also takes care of lowercase letters)

if inp.upper() == letterg[i]:

This line is executed if tge about condition is true; the line calculates the number grade and prints it

print('The numeric value for grade ', inp, ' is ',4 - i)

This line terminates the iteration

break;

If the condition above is not true

else:

This line is executed

print(inp, "is an invalid grade")

Otras preguntas

ACCESS MORE