163k views
2 votes
7.4 Code Practice: Question 2

Adjust the code you wrote for the last problem to allow for weighted classes. Add a parameter weighted ( 1 = yes, 0 = no) and then return the correct number for the GPA. Weighted classes get one extra point on the GPA value.

I could really use some help on this and 7.5 (I’ll ask that question for 7.5 later)

7.4 Code Practice: Question 2 Adjust the code you wrote for the last problem to allow-example-1

1 Answer

2 votes

def GPAcalc(grade, weighted):

grade = grade.lower()

dictionary = {"a": 4, "b": 3, "c": 2, "d": 1, "f": 0}

if weighted == 1 and grade in dictionary:

return "Your GPA score is: "+str(dictionary[grade] + 1)

elif weighted == 0 and grade in dictionary:

return "Your GPA score is : "+str(dictionary[grade])

else:

return "Invalid"

print(GPAcalc(input("Input a letter grade: "), int(input("Is it weigthed? (1= yes, 0= no)"))))

I modified the code a bit to cut down on the use of if and elif statements. If you need me to change it, I will. Best of luck.

User Moorthy GK
by
5.4k points