What we'll build#
A report card system that a teacher or institute could actually use:
- Store students and their marks in several subjects.
- Calculate total, percentage, grade and pass/fail for each student.
- Print a neat report card for every student.
- Rank the class and find subject toppers.
- Save the results to a CSV file that opens in Excel.
Concepts used: dictionaries, lists, functions, loops, conditionals, f-string formatting, sorted() with key, and file handling.
Step 1: Design the data#
Each student is a dictionary; the class is a list of these dictionaries:
students = [
{"roll": 1, "name": "Asha Verma", "marks": {"Maths": 92, "Science": 88, "English": 79, "Computer": 95}},
{"roll": 2, "name": "Ravi Kumar", "marks": {"Maths": 65, "Science": 72, "English": 58, "Computer": 81}},
...
]
किसी भी project की शुरुआत data को सही ढंग से organise करने से होती है। यहाँ हर student एक dictionary है (roll, name, marks), और marks भी एक dictionary है (subject → marks)। पूरी class इन dictionaries की एक list है।
ऐसा structure रखने से आगे की हर चीज़ - total, percentage, ranking - आसान हो जाती है। Real projects (जैसे database या Excel) में भी data इसी तरह rows और columns में होता है।
Step 2: Small functions for calculations#
Each function does one job - easy to test and reuse:
Step 3: Print one report card#
Step 4: The complete program#
Now combine everything: report cards for all students, ranking, class average, subject toppers and CSV export. Run it, then try adding a new student or subject.
On your computer, open report_cards.csv in Excel or Google Sheets - you'll see a proper table.
Step 5: Ideas to extend the project#
Try these on your own computer - each one practises a different skill:
- Take input - ask the user how many students, then read names and marks with
input(), validating marks withtry/except. - Load from CSV - read student data from a CSV file instead of writing it in code.
- Use classes - convert each student into a
Studentclass with methodstotal(),percentage(),grade(). - Menu - add a
while Truemenu: 1) Add student 2) Show report 3) Ranking 4) Save 5) Exit. - Charts - install
matplotliband draw a bar chart of percentages.
Summary#
You built a real program by combining:
- Data modelling with lists of dictionaries
- Functions with one job each
- Formatting with f-string alignment for tables
- Sorting with
key=for ranking - File handling with the
csvmodule