Create a program, gpacalc.py, that takes four letter grade arguments and prints out the corresponding GPA, to two decimals. Your program should accept both upper-case and lower-case arguments. import sys g = str(sys.argv[1]) def gpa_calc(): points = 0 i = 0 dict = {"A": 4, "A-": 3.67, "B+": 3.33, "B": 3.0, "B-": 2.67, "C+": 2.33, "C": 2.0, "C-": 1.67, "D+": 1.33, "D": 1.0, "F": 0} gpa = 0 # count = 0 if grades: for grade in grades: if grade.upper() in grades: gpa += dict[grade.upper()] points += dict[grade.upper()] gpa = points / len(grades) return gpa else: return None grades = [g] print("My GPA is %.2f " % gpa_calc()) -------------------------------------------------------------------------- Note: It should pass the sys argv command line as illustrated below and do not use ''' print(input())'' in your code answer.
Please review and correct my code, below. It calculates for some, but not correctly do when input different grade letters.
Note: It should pass the sys argv command line as illustrated below and do not use ''' print(input())'' in your code answer.
Q: Create a program, gpacalc.py, that takes four letter grade arguments and prints out the corresponding GPA, to two decimals. Your program should accept both upper-case and lower-case arguments.
import sys
g = str(sys.argv[1])
def gpa_calc():
points = 0
i = 0
dict = {"A": 4, "A-": 3.67, "B+": 3.33, "B": 3.0, "B-": 2.67, "C+": 2.33,
"C": 2.0, "C-": 1.67, "D+": 1.33, "D": 1.0, "F": 0}
gpa = 0
# count = 0
if grades:
for grade in grades:
if grade.upper() in grades:
gpa += dict[grade.upper()]
points += dict[grade.upper()]
gpa = points / len(grades)
return gpa
else:
return None
grades = [g]
print("My GPA is %.2f " % gpa_calc())
--------------------------------------------------------------------------
Note: It should pass the sys argv command line as illustrated below and do not use ''' print(input())'' in your code answer.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images