HOSTEL COMPLAINT SYSTEM (1st Semester Python Project)
Console Based
Hostel Complaints System
A complete breakdown of how this Python project works: file based persistence, complaint classification, admin moderation, and the logic inside every core function.
First semester project: structured file storage without any external database.
What the program does
Python based complaint management system for hostels. Uses plain text files inside a Data/ folder to store everything: individual complaint files, a serial counter, an active index, and a resolved archive. The system survives restarts and requires no setup.
serial_counter.txt ensures unique IDs across runs.complaint_N.txt) + index file for quick listing. Resolved moved to archive.os.path.join and os.makedirs to work on Windows, Linux, macOS without changes.File system infrastructure
All data lives inside a Data/ folder next to the script. Inside, a complaints/ directory holds every complaint as a separate text file. The program creates everything automatically if missing.
import os script_dir = os.path.dirname(os.path.abspath(__file__)) data_dir = os.path.join(script_dir, "Data") complaints_dir = os.path.join(data_dir, "complaints") os.makedirs(complaints_dir, exist_ok=True) serial_file = os.path.join(data_dir, "serial_counter.txt") index_file = os.path.join(data_dir, "complaint_index.txt") resolved_file = os.path.join(data_dir, "resolved_complaints.txt")
├── serial_counter.txt
├── complaint_index.txt
├── resolved_complaints.txt
└── complaints/
├── complaint_1.txt
├── complaint_2.txt
└── ...
Serial number generator
Atomic increment operation. Reads the current value, adds one, writes back, and returns the new serial. The r+ mode and seek(0) ensure the file is overwritten from the beginning.
def get_next_serial(): with open(serial_file, "r+") as f: serial = int(f.read()) + 1 f.seek(0) f.write(str(serial)) return serial
seek(0) moves it back to the start before writing, so we overwrite the old value instead of appending.
Complaint categories
Six main categories mapped to specific subcategories using a dictionary. Users first pick a main category, then a subcategory from a dynamic list. The "Other" option allows custom subcategory input.
subcategories = {
"Food Issues": ["Food Quality", "Meal Timings", "Canteen Staff Behavior", "Other"],
"Water Supply": ["Drinking Water Problems", "Wash Water Issues", "Other"],
"Electricity Problems": ["Power Outages", "Voltage Issues", "Other"],
"Internet Issues": ["No Internet Access", "Slow Internet Speed", "Other"],
"Room Maintenance": ["Room Cleaning Required", "Bathroom Not Cleaned", "Broken Items", "Other"],
"Other Complaints": ["User Defined"]
}
Submitting a complaint
The submission process collects name, room, category, subcategory, and details. It then generates a serial number, writes a detailed complaint file inside the complaints/ directory, and appends a summary line to complaint_index.txt.
filename = os.path.join(complaints_dir, f"complaint_{serial}.txt") with open(filename, "w") as f: f.write(f"Complaint No: {serial}\n") f.write(f"Name: {name}\n") f.write(f"Room: {room}\n") f.write(f"Main Category: {category}\n") f.write(f"Sub Category: {subcategory}\n") f.write(f"Complaint: {details}\n") file_append(index_file, f"{serial} | {name} | Room {room} | {category}")
Admin authentication
Simple hardcoded password check. While not secure for production, it demonstrates a basic access control layer for a console project. The password is stored directly in the function.
def admin_login(): password = input("Enter admin password: ") return password == "admin123"
Access granted.
Admin Panel:
1. View Current Complaints
2. View Resolved Complaints
3. Logout
Select an option: _
Viewing and resolving complaints
The admin reads complaint_index.txt to display all unresolved complaints. Entering a serial number shows the full complaint file and offers to mark it as resolved.
def resolve_complaint(serial): with open(index_file, "r") as f: lines = f.readlines() new_lines = [] resolved_line = "" for line in lines: if line.startswith(f"{serial} "): resolved_line = line else: new_lines.append(line) with open(index_file, "w") as f: f.writelines(new_lines) file_append(resolved_file, resolved_line.strip())
startswith to avoid partial matches), writes back the remaining lines, and appends the removed line to the resolved archive. The original complaint file stays untouched.
File formats
Three core text files maintain the system state. Everything is plain text, human readable, and easy to debug.
6 | Sara | Room 207 | Electricity Problems
4 | Zain | Room 089 | Room Maintenance
Full execution map
What this teaches
r+ and seek to safely increment a counter without race conditions.os.path.join and os.makedirs make the code run anywhere.From physical register to digital system
The idea came from our hostel's messy physical complaint register: just a notebook with no organization. I started with an execution map on a page, improving it again and again as I added parts to overcome limitations. When I began coding, if I could not implement something complex, I changed it into a simpler solution that still worked. I built it step by step, using basic tools like lists and text files, until it became a complete system. It taught me that starting with a clear personal idea and adapting as you go turns a concept into a real working program.
If you want to extend this project: add timestamps, implement complaint searching, allow students to track status, or convert the file storage to SQLite. The structure is ready for incremental improvement.