AiTechWorlds
AiTechWorlds
You've learned how to write variables, make decisions, repeat actions, create functions, work with lists and dictionaries, build classes, and debug errors. Now it's time to bring every one of those skills together into one real, working project.
This is what programming actually feels like: starting with a real-world need, breaking it into pieces, and building each piece until you have something that genuinely works.
Client: A high school teacher with 30+ students
Problem: Tracking student grades across multiple subjects in a spreadsheet is slow and error-prone
Solution: A Python program that manages student records, calculates grades, and generates reports
This is a real type of project. Educational software is a massive industry. What you build here is the foundation of systems used in schools worldwide.
Before writing a single line of code, we define what the program must do:
First, we design the Student class. It stores everything about one student:
class Student:
"""Represents a single student with grades."""
def __init__(self, name, student_id):
self.name = name
self.student_id = student_id
self.grades = {} # {subject: score}
def add_grade(self, subject, score):
"""Add or update a grade for a subject."""
if not (0 <= score <= 100):
print(f" ✗ Score must be between 0 and 100 (got {score})")
return False
self.grades[subject] = score
print(f" ✓ Added: {subject} = {score}")
return True
def get_average(self):
"""Calculate the average score across all subjects."""
if not self.grades:
return 0.0
return sum(self.grades.values()) / len(self.grades)
def get_letter_grade(self):
"""Convert numerical average to a letter grade."""
avg = self.get_average()
if avg >= 90: return 'A'
elif avg >= 80: return 'B'
elif avg >= 70: return 'C'
elif avg >= 60: return 'D'
else: return 'F'
def get_grade_for_subject(self, subject):
"""Return letter grade for a specific subject score."""
score = self.grades.get(subject, 0)
if score >= 90: return 'A'
elif score >= 80: return 'B'
elif score >= 70: return 'C'
elif score >= 60: return 'D'
else: return 'F'
def print_report(self):
"""Display a formatted grade report for this student."""
print(f"\n{'='*45}")
print(f" Student Report")
print(f" Name: {self.name}")
print(f" ID: {self.student_id}")
print(f"{'='*45}")
if not self.grades:
print(" No grades recorded yet.")
else:
print(f" {'Subject':<20} {'Score':>6} {'Grade':>5}")
print(f" {'-'*37}")
for subject, score in sorted(self.grades.items()):
letter = self.get_grade_for_subject(subject)
print(f" {subject:<20} {score:>6.1f} {letter:>5}")
print(f" {'-'*37}")
avg = self.get_average()
letter = self.get_letter_grade()
print(f" {'AVERAGE':<20} {avg:>6.1f} {letter:>5}")
print(f"{'='*45}")
def __str__(self):
return f"{self.name} (ID: {self.student_id}) — {len(self.grades)} subjects, Avg: {self.get_average():.1f} ({self.get_letter_grade()})"
Now we build the system that manages all students:
class GradeManagementSystem:
"""Manages a collection of students and their grades."""
def __init__(self):
self.students = {} # {student_id: Student object}
def add_student(self, name, student_id):
"""Add a new student to the system."""
if student_id in self.students:
print(f" ✗ Student ID '{student_id}' already exists")
return False
self.students[student_id] = Student(name, student_id)
print(f" ✓ Added student: {name} (ID: {student_id})")
return True
def find_student(self, student_id):
"""Find a student by ID. Returns None if not found."""
return self.students.get(student_id, None)
def add_grade(self, student_id, subject, score):
"""Add a grade for a student."""
student = self.find_student(student_id)
if student is None:
print(f" ✗ No student with ID '{student_id}'")
return False
return student.add_grade(subject, score)
def get_class_average(self):
"""Calculate the average across all students."""
if not self.students:
return 0.0
averages = [s.get_average() for s in self.students.values() if s.grades]
return sum(averages) / len(averages) if averages else 0.0
def print_all_reports(self):
"""Print reports for all students."""
if not self.students:
print(" No students in the system.")
return
for student in self.students.values():
student.print_report()
def print_class_summary(self):
"""Print a summary of all students."""
if not self.students:
print(" No students in the system.")
return
print(f"\n{'='*55}")
print(f" CLASS SUMMARY")
print(f"{'='*55}")
print(f" {'Name':<20} {'ID':<10} {'Avg':>6} {'Grade':>5}")
print(f" {'-'*51}")
grade_counts = {'A': 0, 'B': 0, 'C': 0, 'D': 0, 'F': 0}
for student in self.students.values():
letter = student.get_letter_grade()
grade_counts[letter] += 1
avg = student.get_average()
print(f" {student.name:<20} {student.student_id:<10} {avg:>6.1f} {letter:>5}")
print(f" {'-'*51}")
class_avg = self.get_class_average()
print(f" {'CLASS AVERAGE':<30} {class_avg:>6.1f}")
print(f"\n Grade Distribution:")
for grade, count in grade_counts.items():
bar = "█" * count
print(f" {grade}: {bar} ({count})")
print(f"{'='*55}")
def get_valid_input(prompt, input_type=str, min_val=None, max_val=None):
"""Keep asking until we get valid input."""
while True:
try:
value = input_type(input(prompt).strip())
if min_val is not None and value < min_val:
print(f" Value must be at least {min_val}")
continue
if max_val is not None and value > max_val:
print(f" Value must be at most {max_val}")
continue
return value
except ValueError:
print(f" Invalid input. Please enter a valid {input_type.__name__}.")
def main():
system = GradeManagementSystem()
print("╔══════════════════════════════════════╗")
print("║ Student Grade Management System ║")
print("║ AiTechWorlds Academy ║")
print("╚══════════════════════════════════════╝")
while True:
print("\n┌─────────── MAIN MENU ───────────┐")
print("│ 1. Add new student │")
print("│ 2. Add/update grade │")
print("│ 3. View student report │")
print("│ 4. View all student reports │")
print("│ 5. View class summary │")
print("│ 6. Exit │")
print("└──────────────────────────────────┘")
choice = input("Select option (1-6): ").strip()
if choice == "1":
print("\n── Add New Student ──")
name = input(" Student name: ").strip()
if not name:
print(" ✗ Name cannot be empty")
continue
sid = input(" Student ID: ").strip().upper()
if not sid:
print(" ✗ Student ID cannot be empty")
continue
system.add_student(name, sid)
elif choice == "2":
if not system.students:
print("\n No students yet. Add a student first.")
continue
print("\n── Add Grade ──")
print(" Current students:")
for sid, student in system.students.items():
print(f" {sid}: {student.name}")
sid = input(" Enter student ID: ").strip().upper()
subject = input(" Subject name: ").strip()
if not subject:
print(" ✗ Subject cannot be empty")
continue
score = get_valid_input(" Score (0-100): ", float, 0, 100)
system.add_grade(sid, subject, score)
elif choice == "3":
if not system.students:
print("\n No students yet.")
continue
print("\n── Student Report ──")
sid = input(" Enter student ID: ").strip().upper()
student = system.find_student(sid)
if student:
student.print_report()
else:
print(f" ✗ No student with ID '{sid}'")
elif choice == "4":
print("\n── All Student Reports ──")
system.print_all_reports()
elif choice == "5":
print()
system.print_class_summary()
elif choice == "6":
print("\n Goodbye! All data will be cleared.")
break
else:
print(" ✗ Invalid option. Please enter 1-6.")
if __name__ == "__main__":
main()
╔══════════════════════════════════════╗
║ Student Grade Management System ║
║ AiTechWorlds Academy ║
╚══════════════════════════════════════╝
Select option (1-6): 1
── Add New Student ──
Student name: Alice Johnson
Student ID: S001
✓ Added student: Alice Johnson (ID: S001)
Select option (1-6): 2
── Add Grade ──
Current students:
S001: Alice Johnson
Enter student ID: S001
Subject name: Mathematics
Score (0-100): 92
✓ Added: Mathematics = 92.0
Select option (1-6): 5
═══════════════════════════════════════════════════════
CLASS SUMMARY
═══════════════════════════════════════════════════════
Name ID Avg Grade
───────────────────────────────────────────────────
Alice Johnson S001 92.0 A
CLASS AVERAGE 92.0
Grade Distribution:
A: █ (1)
B: (0)
C: (0)
═══════════════════════════════════════════════════════
Every concept from this course appears in this project:
| Concept | Where Used |
|---|---|
| Variables & data types | name, score, student_id |
if/elif/else | Grade calculation, input validation, menu options |
for loops | Iterating students, printing reports |
while loop | Menu loop, input validation loop |
| Functions | get_valid_input(), main() |
| Parameters & return | All methods with inputs and outputs |
| Lists | Grade distributions, averages |
| Dictionaries | self.grades, self.students |
| Classes & objects | Student, GradeManagementSystem |
| Methods | add_grade(), print_report(), etc. |
__str__ | Student.__str__ |
| Error handling | try/except in get_valid_input() |
| f-strings | All formatted output |
You've built a complete working program from scratch. Here's what comes next in your programming journey:
Immediate next steps:
Directions to explore:
The program you built today is the foundation of software worth tens of thousands of dollars in the education industry. You understand how to think like a programmer. Keep building — every project teaches you something the next one will use.
Welcome to programming. You belong here.
Get this course's notes on Telegram!
Free cheat sheets, summaries & practice exercises