import datetime
import sys
class StudentManagementSystem:
def __init__(self):
self.students = []
self.courses = []
self.passed_courses = []
def add_student(self):
first_name = input("Enter the first name of the student: ")
last_name = input("Enter the last name of the student: ")
major = input("Select student's major (CE, EE, ET, ME, SE): ")
if not first_name.isalpha() or not last_name.isalpha() or not first_name.istitle() or not last_name.istitle():
print("Names should contain only letters and start with capital letters.")
return
current_year = datetime.datetime.now().year
student_id = random.randint(10000, 99999)
email = f"{first_name.lower()}.{last_name.lower()}@lut.fi"
student_data = (student_id, first_name, last_name, current_year, major, email)
self.students.append(student_data)
with open("students.txt", "a") as file:
file.write(','.join(map(str, student_data)) +
print("Student added successfully!")
def search_items(self, file_path, search_term, item_type):
if len(search_term) < 3:
print("Search term should contain at least 3 characters.")
return
with open(file_path, "r") as file:
items = file.readlines()
matching_items = [item for item in items if search_term in item]
if matching_items:
print(f"Matching {item_type}s:")
for item in matching_items:
item_info = item.strip().split(",")
print(f"ID: {item_info[0]}, {item_type.capitalize()}: {item_info[1]}")
else:
print(f"No matching {item_type}s found.")
def search_student(self):
search_term = input("Give at least 3 characters of the student's first or last name: ")
self.search_items("students.txt", search_term, "student")
def search_course(self):
search_term = input("Give at least 3 characters of the course name or teacher's name: ")
self.search_items("courses.txt", search_term, "course")
def add_course_completion(self):
# Functionality for adding course completion
pass
def show_student_record(self):
# Functionality for displaying student records
pass
def main_menu(self):
print("You may select one of the following:")
print("1) Add student")
print("2) Search student")
print("3) Search course")
print("4) Add course completion")
print("5) Show student's record")
print("0) Exit")
choice = input("What is your selection? ")
if choice == "1":
self.add_student()
elif choice == "2":
self.search_student()
elif choice == "3":
self.search_course()
elif choice == "4":
self.add_course_completion()
elif choice == "5":
self.show_student_record()
elif choice == "0":
print("Exiting the program.")
sys.exit()
else:
print("Invalid input. Please select a valid option.")
if __name__ == "__main__":
system = StudentManagementSystem()
while True:
system.main_menu()