Question: My code was not correct when I ran the example 1; I got 53.00 for total quality points. def main(): # print title print('Semester grades
My code was not correct when I ran the example 1; I got 53.00 for total quality points.
def main(): # print title print('Semester grades and status for one student ') # initialize total quality points and total credit hours total_quality_points = 0 total_credit_hours = 0 # ask user for number of classes num_classes = int(input('Input number of classes for this student: '))
# for each class (loop control structure) for i in range(1, num_classes+1): # print class number print('Please enter information for class', i) # input quality points and credit hours letter_grade = input(' letter grade? ') credit_hours = float(input(' credit hours? ')) # convert letter grade to quality points using if-elif (control structure) if letter_grade == 'A': quality_points = 4.0 elif letter_grade == 'B': quality_points = 3.0 elif letter_grade == 'C': quality_points == 2.0 elif letter_grade == 'D': quality_points == 1.0 elif letter_grade == 'E': quality_points == 0.0 # if letter grade is invalid else: # print error message, assign zero quality points print(' *** No quality points awarded for invalid grade ***') quality_points == 0.0 # add quality points * credit hours to total_quality_points total_quality_points += quality_points * credit_hours # add credit hours to total_credit_hours total_credit_hours += credit_hours # if total_credit_hours is not zero, if total_credit_hours != 0: # divide total_quality_points by total_credit_hours to get gpa gpa = total_quality_points / total_credit_hours # otherwise gpa is a 0 else: gpa = 0.0 # output _______, ______ and gpa (2 decimal places) print() print(f'Total Quality Points: {total_quality_points:.2f}') print(f'Total Credit Hours: {total_credit_hours:.2f}') print(f'Grade Point Average: {gpa:.2f}') # check gpa for special cases: probation and Dean's list using if (control structures) if gpa < 2.0: print('Academic Probation') elif gpa > 3.5 and total_credit_hours >= 12.0:#? print('Dean\'s List')
Sample Run 1:
Semester grades and status for one student Input number of classes for this student: 4 Please enter information for class 1 letter grade? A credit hours? 4 Please enter information for class 2 letter grade? B credit hours? 3.0 Please enter information for class 3 letter grade? A credit hours? 3 Please enter information for class 4 letter grade? C credit hours? 4.0 Total Quality Points: 45.00 Total Credit Hours: 14.00 Grade Point Average: 3.21
Sample Run 2: ( Dean's List )
Semester grades and status for one student Input number of classes for this student: 3 Please enter information for class 1 letter grade? A credit hours? 3 Please enter information for class 2 letter grade? A credit hours? 4 Please enter information for class 3 letter grade? A credit hours? 5 Total Quality Points: 48.00 Total Credit Hours: 12.00 Grade Point Average: 4.00 Dean's List
Sample Run 3: (with invalid grade and Academic Probation)
Semester grades and status for one student Input number of classes for this student: 1 Please enter information for class 1 letter grade? Yes credit hours? 3 *** No quality points awarded for invalid grade *** Total Quality Points: 0.00 Total Credit Hours: 3.00 Grade Point Average: 0.00 Academic Probation
The algorithm for calculating a GPA is to translate each letter grade to a number of quality points (A=4, B=3, C=2, D=1, E=0) and multiply each grade by the number of credit hours for that class. The total of these products is divided by the total number of credit hours. So the Sample Run 1 above would calculate as 4*4 + 3*3 + 3*4 + 4*2 = 45 for quality points and 4 + 3 + 3 + 4 = 14.0 credit hours. 45.0/14.0 = 3.21 (formatted to 2 places).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
