-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent-queue-system.py
More file actions
77 lines (67 loc) · 2.05 KB
/
Copy pathevent-queue-system.py
File metadata and controls
77 lines (67 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Event Queue System
This program manages an event queue.
It allows users to:
- Add a new event
- Process the next event in the queue
- Display all pending events
- Cancel a specific event
- Exit the system
"""
# List to store events
event_queue = []
# Function to add a new event
def add_event(event):
event_queue.append(event)
print(f"Event '{event}' added to the queue.")
# Function to process the next event
def process_next_event():
if event_queue:
event = event_queue.pop(0)
print(f"Processed event: '{event}'")
else:
print("No events to process.")
# Function to display all pending events
def display_pending_events():
if event_queue:
print("Pending Events:")
for idx, event in enumerate(event_queue, 1):
print(f"{idx}. {event}")
else:
print("No pending events.")
# Function to cancel a specific event
def cancel_event(event_name):
if event_name in event_queue:
event_queue.remove(event_name)
print(f"Event '{event_name}' has been canceled.")
else:
print(f"Event '{event_name}' not found or already processed.")
# Main program loop
while True:
print("\nEVENT MENU")
print("1. Add Event")
print("2. Process Next Event")
print("3. Display Pending Events")
print("4. Cancel an Event")
print("5. Exit")
try:
choice = int(input("Enter your choice: "))
if choice < 1 or choice > 5:
print("Please choose a number between 1 and 5.")
continue
except ValueError:
print("Invalid input. Please enter a number.")
continue
if choice == 1:
event = input("Enter event name: ")
add_event(event)
elif choice == 2:
process_next_event()
elif choice == 3:
display_pending_events()
elif choice == 4:
event_name = input("Enter event name to cancel: ")
cancel_event(event_name)
elif choice == 5:
print("Exiting event processing system.")
break