Challenge 2: Letter Grade to GPA

Write a function to calculate the GPA of a student when given the grade.

Problem Statement

There are many school systems that give standardized GPA points instead of letter grades and vice versa. To bring all these institutions on the same grade scale, we have hired you! Your job is to take a letter grade and change it to the required GPA point.

Write a method called gpaPoint that takes in a string value and returns the correct decimal GPA point, with respect to the scale given below:

  • A+: 4
  • A: 4
  • A-: 3.7
  • B+: 3.3
  • B: 3
  • B-: 2.8
  • C+: 2.5
  • C: 2
  • C-: 1.8
  • D: 1.5
  • F: 0

If any other grade is given, simply return a -1.

Hint: Revise conditionals and see what helps keep your code short and brief.

Input

a string grade

Output

a floating point value corresponding to the letter grade

Sample Input

B-

Sample Output

2.8

Coding Exercise

Write your code in the code widget below. If you don’t get it right, don’t worry; the solution is also given.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy