1+ import calendar
2+
3+ # A dictionary to store events by date
4+ events = {}
5+
16def display_cal (year_input , month_input ):
27 """
38 Display a calendar for the desired year and month.
4-
5- Parameters:
6- year_input (int): The year for which the calendar is to be displayed.
7- month_input (int): The month for which the calendar is to be displayed.
8-
99 """
10- import calendar
11-
1210 print (calendar .month (year_input , month_input ))
13-
11+ display_events ( year_input , month_input )
1412
1513def fetch_year ():
1614 """
@@ -25,7 +23,6 @@ def fetch_year():
2523 except ValueError :
2624 print ("Invalid input. Please enter a valid year." )
2725
28-
2926def fetch_month ():
3027 """
3128 Function that asks the user to enter a month, validates the input, and returns the valid month.
@@ -39,8 +36,94 @@ def fetch_month():
3936 except ValueError :
4037 print ("Invalid input. Please enter a valid month." )
4138
39+ def add_event (year_input , month_input ):
40+ """
41+ Add an event to a specific date.
42+ """
43+ day_input = int (input ("Enter day for the event (1-31): " ))
44+ event_title = input ("Enter event title: " )
45+
46+ # Validate the day
47+ if day_input < 1 or day_input > 31 :
48+ print ("Invalid day. Please enter a day between 1 and 31." )
49+ return
50+
51+ # Store event in dictionary
52+ date_key = f"{ year_input } -{ month_input :02d} -{ day_input :02d} "
53+ events [date_key ] = event_title
54+ print (f"✅ Event '{ event_title } ' added to { date_key } " )
55+
56+ def view_events ():
57+ """
58+ View all added events.
59+ """
60+ if not events :
61+ print ("No events added yet." )
62+ else :
63+ print ("\n Upcoming Events:" )
64+ for date , event in events .items ():
65+ print (f"{ date } - { event } " )
66+
67+ def delete_event ():
68+ """
69+ Deletes an event from the events dictionary.
70+ """
71+ if not events :
72+ print ("No events to delete." )
73+ return
74+
75+ print ("\n Your Events:" )
76+ for idx , (date , event ) in enumerate (events .items (), 1 ):
77+ print (f"{ idx } . { date } - { event } " )
78+
79+ try :
80+ choice = int (input ("Enter the event number to delete: " ))
81+ if 1 <= choice <= len (events ):
82+ date_to_delete = list (events .keys ())[choice - 1 ]
83+ removed_event = events .pop (date_to_delete )
84+ print (f"✅ Event '{ removed_event } ' on { date_to_delete } deleted successfully!" )
85+ else :
86+ print ("❌ Invalid event number." )
87+ except ValueError :
88+ print ("❌ Please enter a valid number." )
89+
90+ def display_events (year_input , month_input ):
91+ """
92+ Display all events for a specific month and year.
93+ """
94+ print ("\n Events in the calendar:" )
95+ for date , event in events .items ():
96+ event_year , event_month , _ = date .split ("-" )
97+ if int (event_year ) == year_input and int (event_month ) == month_input :
98+ print (f"{ date } - { event } " )
99+
100+ def main_menu ():
101+ year_input = fetch_year ()
102+ month_input = fetch_month ()
103+
104+ while True :
105+ print ("\n Menu:" )
106+ print ("1. Display Calendar" )
107+ print ("2. Add Event" )
108+ print ("3. View Events" )
109+ print ("4. Delete Event" )
110+ print ("5. Exit" )
111+
112+ choice = input ("Choose an option: " )
42113
43- year_input = fetch_year ()
44- month_input = fetch_month ()
114+ if choice == "1" :
115+ display_cal (year_input , month_input )
116+ elif choice == "2" :
117+ add_event (year_input , month_input )
118+ elif choice == "3" :
119+ view_events ()
120+ elif choice == "4" :
121+ delete_event ()
122+ elif choice == "5" :
123+ print ("Exiting..." )
124+ break
125+ else :
126+ print ("Invalid option! Please try again." )
45127
46- display_cal (year_input , month_input )
128+ if __name__ == "__main__" :
129+ main_menu ()
0 commit comments