Question
In python language, modify the following code to allow for weighted classes def GPAcalc(letterGrade): letterGrade = letterGrade.lower() if letterGrade=='a': return 4 elif letterGrade=='b': return 3
In python language, modify the following code to allow for weighted classes
def GPAcalc(letterGrade):
letterGrade = letterGrade.lower()
if letterGrade=='a':
return 4
elif letterGrade=='b':
return 3
elif letterGrade == 'c':
return 2
elif letterGrade == 'd':
return 1
elif letterGrade == 'f':
return 0
else:
return "Invalid"
def main():
letterGrade = input("Enter your Letter Grade: ")
print("Your GPA score is:",GPAcalc(letterGrade))
main()
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.
Input: Letter Grade | Expected output: Non-weighted GPA value | Expected output: Weighted GPA value |
A | 4 | 5 |
B | 3 | 4 |
C | 2 | 3 |
D | 1 | 2 |
F | 0 | 1 |
Anything else | Invalid | Invalid |
Sample Run 1
Enter your Letter Grade: B
Is it weighted? (1 = yes, 0 = no) 1
Your GPA score is : 4
Sample Run 2
Enter your Letter Grade: B
Is it weighted? (1= yes, 0= no) 0
Your GPA score is: 3
Sample Run 3
Enter your Letter Grade: a
Is it weighted?(1 = yes, 0 = no) 0
Your GPA score is : 4
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started