I’ve been doing this calendar project for many hours and I can’t figure out what is going wrong. I thought I did everything right. I even watched the video to check my work and still can’t find an error. Could someone tell me what I’m doing wrong?
'''
this makes a calendar that can be edited
'''
from time import strftime, sleep
name = 'Robert'
calendar = {}
def welcome():
print 'welcome '+ name
print 'calendar opening...'
sleep(1)
print "Today is: " + strftime("%A %B %d, %Y")
print "The time is: " + strftime("%I:%M:%s")
sleep(1)
print "What would you like to do? "
def start_calendar():
calendar = {}
welcome()
start = True
while start == True:
user_choice = str(raw_input("A to Add, U to Update, V to View, D to Delete, X to Exit: "))
user_choice = user_choice.upper()
if user_choice == "V":
if len(calendar.keys()) == 0:
print "The calendar is empty."
else:
print(calendar)
elif user_choice == "U":
date = input("What date?")
update = input("Enter the update")
Calendar[date] = update
print("The update was processed")
print(calendar)
elif user_choice == "A":
event = raw_input("Enter event: ")
date = raw_input("Enter date (MM/DD/YYYY): ")
if len(date) > 10 or int(date[6:]) < int(strftime("%Y")):
print("Invalid date was entered.")
try_again = input("Try Again? Y for Yes, N for No: ")
try_again = try_again.upper()
if try_again == "Y":
continue
else:
start == False
else:
calendar[date] = event
print("Event added")
print(Calendar)
elif user_choice == "D":
if len(calendar.keys()) < 1:
print("The calendar is empty")
else:
event = raw_input("What event? ")
for date in Calendar.keys():
if event == calendar[date]:
del calendar[date]
print("Event deleted successfully")
print calendar
else:
print("Invalid event")
elif user_choice == "X":
start = False
else:
print("You can only choose from the specified letters")
start_calendar()
.
Here is the error I keep getting. I tried putting calendar in the function to no avail.
$ python Calendar.py
welcome Robert
calendar opening...
Today is: Friday September 07, 2018
The time is: 05:38:1536341919
What would you like to do?
A to Add, U to Update, V to View, D to Delete, X to Exi
t: a
Enter event: deadline
Enter date (MM/DD/YYYY): 01/01/2020
Event added
Traceback (most recent call last):
File "Calendar.py", line 66, in <module>
start_calendar()
File "Calendar.py", line 47, in start_calendar
print(Calendar)
NameError: global name 'Calendar' is not defined
$