You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
print("\nInstructions: Enter the number of weighted assignments, then input each grade (0-100) and its weight (0-100). The total weight must not exceed 100. Use this calculator to determine your overall course grade, assess the impact of assignments, and track your academic progress throughout the semester.")
4
+
5
+
# Initialize an empty list to store each assignment's grade and weight
6
+
assignments= []
7
+
8
+
# Ask the user how many assignments or sections they want to enter
9
+
num=int(input("\nHow many weighted assignments/sections do you have? "))
10
+
11
+
# Track the total weight entered by the user to ensure it doesn't exceed 100
12
+
total_weight=0
13
+
14
+
# Loop through each assignment
15
+
foriinrange(num):
16
+
print("\nAssignment/Section", i+1)
17
+
18
+
# Get a valid grade from the user (between 0 and 100)
19
+
whileTrue:
20
+
grade=float(input(" Enter the grade (0-100): "))
21
+
if0<=grade<=100:
22
+
break
23
+
else:
24
+
print(" Please enter a grade between 0 and 100.")
25
+
26
+
# Get a valid weight from the user and ensure total doesn't exceed 100
27
+
whileTrue:
28
+
weight=float(input(" Enter the weight: "))
29
+
if0<=weight<=100andtotal_weight+weight<=100:
30
+
total_weight+=weight
31
+
break
32
+
else:
33
+
print(" Weight must be between 0 and 100 and total weights cannot exceed 100.")
34
+
35
+
# Store the grade and weight as a dictionary and add to the list
36
+
assignment= {"grade": grade, "weight": weight}
37
+
assignments.append(assignment)
38
+
39
+
40
+
# Function to calculate the weighted overall grade
41
+
defcalculate_grade(assignments):
42
+
total=0
43
+
forainassignments:
44
+
# Multiply each grade by its weight and add to the total
45
+
total+=a["grade"] *a["weight"]
46
+
47
+
# Check to avoid division by zero
48
+
iftotal_weight==0:
49
+
print(" Weight must be between 0 and 100 and total weights cannot exceed 100.")
50
+
else:
51
+
overall=total/total_weight
52
+
returnoverall
53
+
54
+
55
+
# Function to return a motivational message based on the final grade
56
+
defgrade_message(grade):
57
+
ifgrade>=90:
58
+
return"Great job! You're doing excellent!"
59
+
elifgrade>=80:
60
+
return"Good work! Keep it up!"
61
+
elifgrade>=70:
62
+
return"You're getting there, keep pushing!"
63
+
else:
64
+
return"Don't give up! You can improve!"
65
+
66
+
67
+
# Call the calculation function and print the result and message
68
+
overall=calculate_grade(assignments)
69
+
print("\nYour current overall grade is:", overall, "%")
70
+
print(grade_message(overall))
71
+
72
+
# Closing message
73
+
print("\nThanks for using the calculator! Good luck!")
0 commit comments