0

I have an assignment for my class and I do not know what's wrong with it. Here is the assigment:

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.

Here is my code:

grade = input('Enter your letter grade: ')
def GPAcalc(grade):
 if grade == 'a'or grade == 'A':
 print('Your GPA score is: 4')
 elif grade == 'b'or grade == 'B':
 print('Your GPA score is: 3')
 elif grade == 'c'or grade == 'C':
 print('Your GPA score is: 2')
 elif grade == 'D'or grade == 'd':
 print('Your GPA score is: 1')
 elif grade == 'f'or grade == 'F':
 print('Your GPA score is: 0')
 else:
 print('Invalid')
GPAcalc(grade)

Here is the criteria that has failed:

This test case checks that your program is properly using the GPAcalc function to determine output.

This test case runs the GPAcalc function directly and checks the returned value.

This test case runs function directly and checks the returned value.

asked Dec 4, 2020 at 15:10
1
  • 2
    I think the key specification line is It will return either an integer for the GPA value or a string Invalid. You need to return values from your GPAcalc rather than having it print them...return 1, return 2, etc...return "invalid". Commented Dec 4, 2020 at 15:14

2 Answers 2

1

It will return either an integer for the GPA value or a string Invalid

This your function does not! You can do something like:

gpa = dict(zip("abcdf", (4, 3, 2, 1, 0)))
def GPAcalc(grade): 
 return gpa.get(grade.lower(), "Invalid")
grade = input('Enter your letter grade: ')
print("Your GPA score is: {}".format(GPAcalc(grade)))
answered Dec 4, 2020 at 15:20
Sign up to request clarification or add additional context in comments.

3 Comments

I tried this and it passed everything other than: This test case checks that your program is properly using the GPAcalc function to determine output.
Well, I would like to see how that test case is constructed =) One can clearly see that the function is used to determine the output.
Yea its a very wonky program
0
grade = input('Enter your letter grade: ')
def GPAcalc(grade):
 if grade == 'a'or grade == 'A':
 return 4
 elif grade == 'b'or grade == 'B':
 return 3
 elif grade == 'c'or grade == 'C':
 return 2
 elif grade == 'D'or grade == 'd':
 return 1
 elif grade == 'f'or grade == 'F':
 return 0
 else:
 return 'Invalid'
answered Dec 4, 2020 at 15:20

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.