class EmployeeAttendance: def __init__(self, filename): self.filename = filename self.attendance_data = {} self.load_data() def load_data(self): try: with open(self.filename, 'r') as file: lines = file.readlines() for line in lines: employee_id, dates = line.strip().split(':') self.attendance_data[employee_id] = dates.split(',') except FileNotFoundError: self.attendance_data = {} def save_data(self): with open(self.filename, 'w') as file: for employee_id, dates in self.attendance_data.items(): file.write(f"{employee_id}:{','.join(dates)}\n") def mark_attendance(self, employee_id, date): if employee_id in self.attendance_data: if date not in self.attendance_data[employee_id]: self.attendance_data[employee_id].append(date) else: self.attendance_data[employee_id] = [date] def get_attendance(self, employee_id): if employee_id in self.attendance_data: return self.attendance_data[employee_id] else: return [] if __name__ == "__main__": attendance = EmployeeAttendance("attendance.txt") while True: print("1. Mark Attendance") print("2. View Attendance") print("3. Exit") choice = input("Enter your choice: ") if choice == '1': employee_id = input("Enter Employee ID: ") date = input("Enter Date (YYYY-MM-DD): ") attendance.mark_attendance(employee_id, date) attendance.save_data() print("Attendance marked successfully!") elif choice == '2': employee_id = input("Enter Employee ID: ") dates = attendance.get_attendance(employee_id) print("Attendance Dates:", ', '.join(dates)) elif choice == '3': print("Exiting...") break else: print("Invalid choice. Please select a valid option.")