![]() Using a while loop, we prompt the user to enter his/her grades and course units, of which we will append both to grades_unit_list. ![]() ![]() try:Ĭourse_no = int(input( 'How many gradable courses did you offer: ')) A try except block is used to handle value error. Next, we prompt users for the number of gradable courses they offered and we create a counter which we would use in a while loop for inputting the grades and units of each course. Print( 'Your GPA for the semester is ' + str(gpa) + '/5.0.') Gpa = round(total_grade_point / cumulative_unit, 2) Total_grade_point += grades_strength] * grading def calculate_gpa( courses_grades): """Calculates the GPA on 5 unit scale.""" global cumulative_unit Next, we divide total_grade_point by cumulative_unit and round it to two decimal places using the round() function. Next, using the for loop, we sum up the units of each course and also find the total grade points (summation of (grade strength X course unit) of each course). If the global keyword is not used, all changes made to the global variable would be erased once the function ends. We would use the global keyword to ensure we can alter the values of cumulative_unit and total_grade_point and still keep the alteration after the function ends. Each tuple in the list would have two values the first would be the grade, and the second, the course unit. Next, we define the function, calculate_gpa(), which would take a list of tuples, course_grades, as its argument. Grades_strength = # Grade strengthĬourse_grades = # List to contain tuples of grades and unit I will explain it in bits throughout this article. Note: Handle all necessary exceptions and/or edge cases. Computes and returns the student GPA, based on the values provides.Takes as parameters, a list of tuples containing grades and their corresponding units.ECX 30 Days of Code and Design Day 29 GPA Calculator Task
0 Comments
Leave a Reply. |