Python Course Selection System Implementation

System Overview

A course selection system for educational institutions with three primary roles: Student, Administrator, and Instructor.

Core Functionalities

  • Authentication: All users log in with credentials; system identifies role upon successufl login.
  • Course Selection: Students enroll in available courses.
  • User Management: Administrators create student and instructor accounts.
  • Data Viewing:
    • Students view their enrolled courses.
    • Administrators access all student records and enrollment data.
    • Instructors see assigned classes and student rosters.

Role-Specific Workflows

Student

  1. Browse available courses
  2. Select courses
  3. View personal course selections
  4. Exit system

Administrator

  1. Create new courses
  2. Register student accounts
  3. View all courses
  4. View all students
  5. Review student enrollments
  6. Register instructors
  7. Assign classes to instructors
  8. Create class groups
  9. Assign students to classes
  10. Exit system

Instructor

  1. View available courses
  2. See assigned classes
  3. View class rosters
  4. Exit system

Technical Implemantation

File Structure

project/
├── bin/
│   └── start.py         # Entry point
├── conf/
│   └── settings.py      # Path configurations
├── core/
│   ├── auth.py          # Authentication logic
│   └── cores.py         # Main application logic
└── db/                  # Data storage
    ├── courseinfo
    ├── gradeinfo
    ├── select_course
    ├── student_grade
    ├── tearch_grade
    └── userinfo

Key Code Snippets

Entry Point (bin/start.py)

import os
import sys
from core import cores

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(BASE_DIR)

if __name__ == '__main__':
    cores.start()

Configuration (conf/settings.py)

import os

DB_DIR = os.path.join(os.path.dirname(__file__), '../db')

PATHS = {
    'USER_DATA': os.path.join(DB_DIR, 'userinfo'),
    'COURSE_DATA': os.path.join(DB_DIR, 'courseinfo'),
    'ENROLLMENT_DATA': os.path.join(DB_DIR, 'select_course'),
    'CLASS_DATA': os.path.join(DB_DIR, 'gradeinfo'),
    'INSTRUCTOR_ASSIGNMENTS': os.path.join(DB_DIR, 'tearch_grade'),
    'STUDENT_CLASSES': os.path.join(DB_DIR, 'student_grade')
}

Authentication (core/auth.py)

import hashlib
from conf.settings import PATHS

SALT = 'system_salt'

def hash_password(password: str) -> str:
    hasher = hashlib.md5(SALT.encode())
    hasher.update(password.encode())
    return hasher.hexdigest()

def authenticate():
    username = input('Username: ')
    password = input('Password: ')
    
    with open(PATHS['USER_DATA'], 'r') as f:
        for line in f:
            user, pwd_hash, role = line.strip().split('|')
            if user == username and pwd_hash == hash_password(password):
                return {'username': username, 'role': role}
    
    print('Invalid credentials')
    return {'username': None, 'role': None}

Main Application Logic (core/cores.py)

import sys
import pickle
from core.auth import authenticate
from conf.settings import PATHS

class CourseCatalog:
    @staticmethod
    def display_courses():
        with open(PATHS['COURSE_DATA'], 'rb') as f:
            try:
                while True:
                    course = pickle.load(f)
                    print(f"Course: {course.name}, Price: {course.price}, Duration: {course.duration}, Instructor: {course.instructor}")
            except EOFError:
                pass

class Course:
    def __init__(self, name, price, duration, instructor):
        self.name = name
        self.price = price
        self.duration = duration
        self.instructor = instructor

class Student:
    ACTIONS = [
        ('Browse Courses', 'view_catalog'),
        ('Enroll in Course', 'enroll'),
        ('View My Courses', 'view_enrollments'),
        ('Exit', 'exit')
    ]
    
    def __init__(self, username):
        self.username = username
        self.enrolled = []
    
    def view_catalog(self):
        CourseCatalog.display_courses()
    
    def enroll(self):
        CourseCatalog.display_courses()
        course_name = input('Course to enroll: ')
        
        if course_name in self.enrolled:
            print('Already enrolled')
            return
        
        self.enrolled.append(course_name)
        with open(PATHS['ENROLLMENT_DATA'], 'ab') as f:
            pickle.dump({self.username: self.enrolled}, f)
        print(f'Enrolled in {course_name}')
    
    def view_enrollments(self):
        print(f"Your courses: {', '.join(self.enrolled)}")
    
    def exit(self):
        sys.exit()

# Administrator and Instructor classes follow similar patterns
# Full implementation would include all specified functionalities

def start():
    user = authenticate()
    if not user['role']:
        return
    
    role_class = getattr(sys.modules[__name__], user['role'])
    user_instance = role_class(user['username'])
    
    while True:
        print("Available actions:")
        for idx, (desc, _) in enumerate(user_instance.ACTIONS, 1):
            print(f"{idx}. {desc}")
        
        choice = int(input("Selection: ")) - 1
        action_name = user_instance.ACTIONS[choice][1]
        getattr(user_instance, action_name)()

Data Storage

Database files (db/ directory) store:

  • userinfo: User credentials and roles
  • courseinfo: Course details
  • select_course: Student enrollments
  • gradeinfo: Class information
  • tearch_grade: Instructor-class assignments
  • student_grade: Student-class assignments

Tags: python Course Selection System Object-Oriented Programming File-Based Database

Posted on Mon, 03 Aug 2026 16:17:18 +0000 by Exemption