Skip to content

Day 7 — Mini Project & Programmer Thinking

🟢 Day 7 — Mini Project & Programmer Thinking

1️⃣ Why a Mini Project?

Until now, you learned:
Variables & decisions
Loops
Lists & strings
Functions
Dictionaries
Files & error handling
But in isolation.
💡 Real programs are just small pieces working together.

2️⃣ The Project: Student Management System

This project is intentionally simple, but real.

What the Program Should Do

Add a student with marks
View all students
Search for a student
Save data to file
Load data from file
Exit safely

3️⃣ Think Before Coding (MOST IMPORTANT PART)

Before writing any code, answer:

Step 1 — What Data Do We Need?

Student name → string
Student marks → number
Multiple students → dictionary
students = {
"Amit": 85,
"Neha": 90
}

Step 2 — What Actions Are Needed?

Add student
View students
Search student
Save
Load
Each action → function
🧠 One action = one function

4️⃣ Program Flow (Mental Diagram)

START
|
|-- Show menu
|-- Take choice
|-- Call correct function
|-- Repeat until exit
END
💡 This is how every menu-driven program works.

5️⃣ Menu Loop (Core Structure)

while True:
print("1. Add student")
print("2. View students")
print("3. Search student")
print("4. Save & Exit")

choice = input("Enter choice: ")

if choice == "1":
add_student()
elif choice == "2":
view_students()
elif choice == "3":
search_student()
elif choice == "4":
save_to_file()
break
else:
print("Invalid choice")
🧠 This is real-world program structure.

6️⃣ Key Functions (Skeleton, Not Full Code)

Add Student

def add_student(students):
name = input("Enter name: ")
marks = int(input("Enter marks: "))
students[name] = marks

View Students

def view_students(students):
for name, marks in students.items():
print(name, marks)

Search Student

def search_student(students):
name = input("Enter name: ")
if name in students:
print(students[name])
else:
print("Not found")

7️⃣ Saving & Loading Data

Save to File

with open("students.txt", "w") as file:
for name, marks in students.items():
file.write(name + "," + str(marks) + "\n")

Load from File

students = {}

try:
with open("students.txt", "r") as file:
for line in file:
name, marks = line.strip().split(",")
students[name] = int(marks)
except:
pass
💡 File becomes your simple database.

8️⃣ Thinking Like a Programmer (IMPORTANT)

Whenever stuck, ask:
What data do I need?
What steps are required?
Can I break this into functions?
Where can errors occur?
What happens if input is wrong?

9️⃣ Practice Tasks (Extend the Project)

Q1

Add update student marks option.

Q2

Delete a student.

Q3

Prevent duplicate student names.

Q4

Show student with highest marks.

Q5

Validate marks (0–100 only).

Q6

Store data in file after every change.

Q7 (Thinking Question)

If program crashes midway, how can data loss be prevented?

🔑 HINTS (Read Together)

Use if name in students
Use functions for every action
Validate input using try/except
Always think about failure cases
 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.