JE 1:52 27% OO Fido def command add (date, event details calendar) (str, str, di
ID: 3851559 • Letter: J
Question
JE 1:52 27% OO Fido def command add (date, event details calendar) (str, str, dict) str Add event details to the list at calendar[date] Create date if it was not there date: A string date formatted as YYYY-MM-DD event details A string describing the event calendar: The calendar database return: empty string calendar command add 2017-02-28 Python class calendar) calendar 2017-02-28' Python class True command add 2017-03-11 "csCA08 test 2", calendar) calendar 2017-03-11 CSCA08 tests 2 2017-02-28 Python class J) True command add 2017-03-11 go out with friends after test calendar) calendar 2017-03-11' ['CSC A08 test go out with friends after test'] 2017-02 28 Python class' J) True YOUR CODE GOES HERE pass def command show (calendar): (dict) str Returns the list of events for calendar sorted in increasing date order as a string, see examples below for a sample formatting calendar: the database of eventsExplanation / Answer
calendar ={}
def command_add(date, event_details, calendar):
# print("in add")
# print("event",event_details)
if date not in calendar:
calendar[date] = [event_details]
else:
# calendar[date].append(event_details)
# print("existing date",calendar[date])
calendar[date].append(event_details)
command_show(calendar)
def command_help():
return "Help for Calendar. The calendar messages are xyz"
def show_elements(calendar):
print(calendar.items())
command_show(calendar)
def command_show(calendar):
x = input("please enter the command: ")
while True:
try:
if x == 'add':
date = input("please enter a date in format 'yyyy-mm-dd': ")
event_details = input("Please enter an event on the given date: ")
# if dt in calendar:
# calendar[dt] = calendar[dt].append(event_details)
# else:
# calendar[dt] = event_details
command_add(date,event_details,calendar)
return calendar
elif x == 'show':
# print("All the items in the calendar are")
# for k,v in calendar.items():
# print(calendar.items())
show_elements(calendar)
elif x == 'delete':
date = input("Please enter the date for which you want to remove values")
ind = int(input("Enter the index of the value that you want to remove"))
try:
if date in calendar:
del calendar[date][ind]
else:
print("Enter date does not exists")
except Exception as e:
print(e)
elif x == 'help':
command_help()
else:
break
except Exception as e:
print(e)
#for i in range(5):
command_show(calendar)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.