Skip to content

Commit cd55617

Browse files
committed
Create SampleGradeTracker.py
1 parent 1a4818d commit cd55617

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

SampleGradeTracker.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Displaying the title and instructions for the user
2+
print("-------- Weighted Course Grade Calculator --------")
3+
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+
for i in range(num):
16+
print("\nAssignment/Section", i + 1)
17+
18+
# Get a valid grade from the user (between 0 and 100)
19+
while True:
20+
grade = float(input(" Enter the grade (0-100): "))
21+
if 0 <= 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+
while True:
28+
weight = float(input(" Enter the weight: "))
29+
if 0 <= weight <= 100 and total_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+
def calculate_grade(assignments):
42+
total = 0
43+
for a in assignments:
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+
if total_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+
return overall
53+
54+
55+
# Function to return a motivational message based on the final grade
56+
def grade_message(grade):
57+
if grade >= 90:
58+
return "Great job! You're doing excellent!"
59+
elif grade >= 80:
60+
return "Good work! Keep it up!"
61+
elif grade >= 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

Comments
 (0)