Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON: Write a function letter2number() that takes a string representing a lett

ID: 643005 • Letter: P

Question

PYTHON: Write a function letter2number() that takes a string representing a letter grade as a parameter and returns the grade point associated with that grade. The grade letter will be one of A, B, C, D, or F (upper- or lowercase). It may include a plus or minus after the letter. An A corresponds to a grade point of 4, a B to 3, a C to 2, a D to 1, and an F to 0. A plus increases the base grade point by 0.3 and a minus decreases it by 0.3. There is no such thing as an A+ or an F-. If the user provides a string as an argument that doesn't correspond to a valid grade, the function returns the string 'unknown grade'. You MUST use a dictionary for this problem. Any solution that does not involve a dictionary will not earn full credit. The following shows the function as used on several different arguments:

Explanation / Answer

# main() function
def main():
   
    result = letter2number("A-")
    print("letter2number("A-"): ", result)
   
    result = letter2number("c+")
    print("letter2number("c+"): ", result)
   
    result = letter2number("f")
    print("letter2number("f"): ", result)
   
    result = letter2number("E")
    print("letter2number("E"): ", result)
   
main()