I can't see what I did wrong on this calendar project


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...'
  print "Today is: " + strftime("%A %B %d, %Y")
  print "The time is: " + strftime("%I:%M:%s")
  print "What would you like to do? "
def start_calendar():
  calendar = {}
  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."
    elif user_choice == "U":
      date = input("What date?")
      update = input("Enter the update")
      Calendar[date] = update
      print("The update was processed")
    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":
          start == False
        calendar[date] = event
        print("Event added")
    elif user_choice == "D":
      if len(calendar.keys()) < 1:
        print("The calendar is empty")
        event = raw_input("What event? ")
        for date in Calendar.keys():
          if event == calendar[date]:
            del calendar[date]
            print("Event deleted successfully")
            print calendar
            print("Invalid event")
    elif user_choice == "X":
      start = False
      print("You can only choose from the specified letters")

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>
  File "Calendar.py", line 47, in start_calendar
NameError: global name 'Calendar' is not defined


Are there two calendar objects? We can see both Calendar and calendar in the listing.


Please post a link to the project. Thanks.


Even if I remove them it makes no difference. I added the second one inside the function hoping it would help stop the error. I will get rid of it and edit my post. Oh wait I misread your post. I’ll check


Thank you so much I didn’t see it for some reason. I spent hours on that…


Could still use the link, please.

We see both raw_input and input in your code. The former is Python 2, the latter Python 3.


Can’t seem to get the link to load. I click share and it just has a blank box with dots moving back and forth no matter how long I wait.


Just copy it from the location bar.


do you mean this
I have the url but there is a share button that wont load.


The link is all we need. I’ve never used share so cannot comment on how it works.


ah i see
Well I will definitely stop using python 3 stuff in 2


Your code can be converted to version 3 very simply by wrapping all print arguments in parens, and removing raw_ from the input statements. The only other change needed is %S instead of %s in strftime().

I checked what version is running in the exercise… 2.7.12. In that case, change all your input to raw_input. You can still use parens on print so get in the habit.

import sys
print (sys.version)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.