// Data Structures
Sets Mini Project — Attendance Tracker
What you're building
An attendance tracker. You have a fixed list of enrolled students. The user marks who showed up. At the end — present, absent, numbers.
What you need to know first
- Sets — creating, add(), in
- Set operations — difference, intersection
while Truewithbreakinput()len()
The brief
Build a program that:
- Starts with a fixed set of enrolled students
- Starts with an empty set for present students
- Loops — user types a name to mark as present, or
doneto finish - Warns if the name isn't on the enrolled list
- Warns if the student was already marked present
- At the end: prints present students, absent students, and counts
Think before you code
- How do you check if a name is enrolled before marking them present?
- How do you find who was absent — students enrolled but not present?
- How do you avoid marking someone present twice?
Your starting point
enrolled = {"Raven", "Wolf", "Ghost", "Viper", "Bull"}
present = set()
while True:
name = input("Mark present (or 'done'): ").capitalize()
if name == "Done":
break
# your code here
# print summary here
Expected output
Mark present (or 'done'): Raven
Raven marked present.
Mark present (or 'done'): Wolf
Wolf marked present.
Mark present (or 'done'): Fox
Fox is not on the enrolled list.
Mark present (or 'done'): Raven
Raven is already marked present.
Mark present (or 'done'): done
--- Attendance Report ---
Present (3): Bull, Ghost, Raven, Wolf
Absent (2): Bull, Viper
Total enrolled: 5
Heads up!
- Use
into check enrollment before adding to present - Use
inagain to check if already marked present - Absent students = enrolled - present — one line with set difference
- Sets are unordered — sort before printing for clean output
The solution
enrolled = {"Raven", "Wolf", "Ghost", "Viper", "Bull"}
present = set()
while True:
name = input("Mark present (or 'done'): ").capitalize()
if name == "Done":
break
elif name not in enrolled:
print(f"{name} is not on the enrolled list.")
elif name in present:
print(f"{name} is already marked present.")
else:
present.add(name)
print(f"{name} marked present.")
absent = enrolled - present
print("\n--- Attendance Report ---")
print(f"Present ({len(present)}): {', '.join(sorted(present))}")
print(f"Absent ({len(absent)}): {', '.join(sorted(absent))}")
print(f"Total enrolled: {len(enrolled)}")
// resources
// 0 comments
// No comments yet. Be the first.
// leave a comment