7.4 Code Practice 1

Write a program that prompts the user to input a letter grade in either capital or lowercase.
Your program should then output the correct
number of the GPA. See the table below for possible inputs and expected outputs. Your program should define at least one function named
GPACalc that is called from your main program.

The GPACalc function should take exactly one parameter-a string for the letter grade as lower or upper case. It will return either an
integer for the GPA value or a string Invalid, if the letter grade parameter is invalid.

Can someone please help me with this quickly cause I feel like I’m overthinking this

74 Code Practice 1 Write a program that prompts the user to input a letter grade in either capital or lowercase Your program should then output the correct numb class=

Respuesta :

In python 3.8

def GPAcalc(grade):

   if grade.lower() == "a":

       return 4

   elif grade.lower() == "b":

       return 3

   elif grade.lower() == "c":

       return 2

   elif grade.lower() == "d":

       return 1

   elif grade.lower() == "f":

       return 0

   else:

       return "Invalid"

print(GPAcalc(input("Input a letter grade: ")))

I hope this helps!

The program illustrates the use of conditional statements.

Conditional statements are statements whose execution depends on the truth value of the condition.

The program in Python, where comments are used to explain each line is as follows:

#This defines the GPAcalc function

def GPAcalc(grade):

   #This converts grade to lower case

   grade = grade.lower()

   #The following if conditions returns the GPA value depending on the letter grade

   if grade == "a":

       return 4

   elif grade == "b":

       return 3

   elif grade == "c":

       return 2

   elif grade == "d":

       return 1

   elif grade == "f":

       return 0

   #If the letter grade is Invalid, then the function returns Invalid

   else:

       return "Invalid"

#This gets input for grade

grade = input("Letter Grade: ")

#This prints the corresponding GPA value

print("GPA value:",GPAcalc(grade))

At the end of the program, the corresponding GPA value is printed

Read more about similar program at:

https://brainly.com/question/20318287