Write a function letter2number() that takes a string representing a letter grade
ID: 3673539 • Letter: W
Question
Write a function letter2number() that takes a string representing a letter grade as a parameter and returnsthe 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 dictionaryfor 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:
Python 3.4.1 Shell File Edit Shell Debug Optionsindows Help etter2Number ('A 3.7 2.3 >>letter2Number'f') >>letter2Number E') tter2Nurber ('E) unknown grade Ln: 58 Col: 4Explanation / Answer
grades={‘A’:4,’B’:3,’C’:2,’D’:1}
letter2number(‘A’)
if you enter
letter2number(‘F-‘)
It will show unknown
you can use
else if ‘+’ in grade:
grade+=3;
error;
else if if ‘-’ in grade:
grade-=3;
error;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.