Solution
Of course! Below is the solution
code for the Python assignment on
the student attendance system:
```python
# Create an empty dictionary to
# store student attendance
student_attendance = {}
# Function to mark attendance
def mark_attendance(student_id, status):
if status.upper() == "P":
student_attendance[student_id] = "Present"
print("Attendance marked for student", student_id)
elif status.upper() == "A":
student_attendance[student_id] = "Absent"
print("Attendance marked for student", student_id)
else:
print("Invalid attendance status. Please enter 'P' for Present or 'A' for Absent.")
# Function to display attendance
def display_attendance():
print("Attendance:")
for student_id, status in student_attendance.items():
print("Student ID:", student_id, "- Status:", status)
# Main program
print("Student Attendance System\n")
while True:
print("1. Mark Attendance")
print("2. Display Attendance")
print("3. Exit")
choice = input("\nEnter your choice: ")
if choice == "1":
student_id = input("Enter student ID: ")
attendance_status = input("Enter attendance status (P/A): ")
mark_attendance(student_id, attendance_status)
elif choice == "2":
display_attendance()
elif choice == "3":
print("Goodbye!")
break
else:
print("Invalid choice. Please select a valid option.")
```