Welcome to the Console Alarm Clock assessment! This task asks you to build an interactive alarm clock program that runs in the terminal. It focuses on time handling, loops, and user interaction.
Create a program that lets users set, view, and delete alarms, and notifies the user in the console when an alarm time is reached.
- Work with Python's
datetimeandtimemodules - Manage multiple alarms using lists/dictionaries
- Implement loops and sleeping (
time.sleep) for polling the system clock - Validate user input (time formats)
- Optionally implement persistence (save/load alarms) or audio notifications
Your program must:
- Display a menu with at least these options:
1) Set alarm
2) List alarms
3) Delete alarm
4) Exit
- Set alarm:
- Prompt user for a time in
HH:MMformat (either 24-hour or clear instructions for 12-hour with AM/PM). - Validate the input and add the alarm to an in-memory list.
- List alarms:
- Show all scheduled alarms with index numbers.
- Delete alarm:
- Allow user to remove an alarm by index number.
- Alarm triggering:
- The program should check the current time periodically (e.g., every 15–30 seconds) and, when an alarm matches the current time, print a prominent notification such as:
[ALARM] It's 07:30! Wake up!
- The notification should allow the user to choose to snooze (e.g., +5 minutes) or dismiss the alarm.
- Input validation:
- Reject incorrect time formats or out-of-range values with helpful messages.
- (Optional bonuses):
- Support multiple alarms and concurrent notifications.
- Save/load alarms to/from a file (JSON) for persistence across runs.
- Play a short sound using the system speaker or a small audio library (note: avoid external dependencies where possible).
- Add repeat options (e.g., weekdays only).
- Save your file as:
alarm.py
- Run in terminal:
python alarm.pyor
python3 alarm.pyNotes:
- While
check_alarmsis running it will block the menu; use Ctrl+C to return. - For more responsive behavior or GUI-like concurrency, consider threading (optional).
Alarm Clock
1) Set alarm
2) List alarms
3) Delete alarm
4) Check/wait for alarms
5) Exit
Enter choice: 1
Enter alarm time (HH:MM, 24-hour): 07:30
Alarm set for 07:30.
Enter choice: 4
Waiting for alarms... (press Ctrl+C to return to menu)
[ALARM] It's 07:30! Wake up!
Snooze for 5 minutes? (yes/no): yes
Alarm snoozed to 07:35.
(press Ctrl+C to return to menu)
Enter choice: 2
1. 07:35
Enter choice: 5
Goodbye!
-
Use JSON to save alarms and reload them on start
-
Implement snooze durations configurable by user
-
Allow recurring alarms (daily or weekdays only)
-
Use threading to check alarms in background while menu remains responsive
-
Play a simple beep or short audio file when alarm triggers (platform-dependent)
When finished:
git add alarm.py
git commit -m "Complete alarm clock assessment"
git push origin main-
datetimemodule docs: https://docs.python.org/3/library/datetime.html -
time.sleep()docs: https://docs.python.org/3/library/time.html
Tip: For testing, set alarms a minute or two ahead so you can verify behavior quickly.