7.4 Code Practice 1

The later academics question and answer asked students to express what they admit is the most important thing for a student to do in order for you to hit success. Of the numerous replies, one which that stood out was practice. Successful persons are certainly not born successful; they become successful by just hard work and commitment. This is how you can reach your goals. These are are one of the answer and question example that you could certainly implement to practice and improve your information and also give you insights that may assist you to maintain your study in school.

Question:

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

Answer:

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

READ MORE  How can saving time increase productivity?

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:

From the answer and question examples above, hopefully, they could simply guide the student deal with the question they had been looking for and take notice of all the things declared in the answer above. You can then have a discussion with your classmate and continue the school learning by studying the topic with one another.

Leave a Reply

Your email address will not be published.