Unit 3 Sections 12 and 13 HW
Python Procedure which can help me in school
def homework_organizer(assignments):
# Sort the homework assignments by due date
sorted_assignments = sorted(assignments, key=lambda x: x[1])
# Print the sorted homework assignments
for assignment in sorted_assignments:
print(assignment[0], "is due on", assignment[1])
assignments = [
("Calc HW", "2022-12-13"),
("CS Hacks", "2022-12-12"),
("Physics pendulum mini lab", "2022-12-12"),
("CS Presentation", "2022-12-14")
]
homework_organizer(assignments)
This procedure takes a list of homework assignments as input and sorts them by their due date. Then, it prints each assignment and its corresponding due date in order.
def calculate_gpa(grades, credits):
total_credits = 0
total_grade_points = 0
# Loop through the grades and credits and calculate the total
# number of credits and grade points
for i in range(len(grades)):
grade = grades[i]
credit = credits[i]
if grade == "A":
grade_points = 4.0
elif grade == "B":
grade_points = 3.0
elif grade == "C":
grade_points = 2.0
elif grade == "D":
grade_points = 1.0
else:
grade_points = 0.0
total_credits += credit
total_grade_points += grade_points * credit
# Calculate and return the GPA
gpa = total_grade_points / total_credits
return gpa
# Example usage
grades = ["A", "A", "A", "B"]
credits = [3, 3, 3, 2]
gpa = calculate_gpa(grades, credits)
print("Your GPA is", gpa)
This procedure takes two lists as input: one for the grades of your courses and one for the number of credits of each course. It calculates your GPA by converting each grade to grade points (A = 4.0, B = 3.0, etc.), multiplying the grade points by the number of credits of the course, and then dividing the total number of grade points by the total number of credits.