Command Line Calendar: What's wrong with my code?


#1

I'm confused as to what's going wrong. I keep getting the error
Traceback (most recent call last):
File "Calendar.py", line 68, in
start_calendar()
File "Calendar.py", line 22, in start_calendar
user_choice = raw_input("Please choose A to
Add, U to Update, V to View, X to Exit. ")
UnboundLocalError: local variable 'raw_input' re
ferenced before assignment

from time import sleep, strftime
name="Rachel"
calendar= {}
def welcome():
  print "Hello %s!" %(name)
  print "Your calendar is 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():
  welcome()
  start = True
  while start:
    user_choice = raw_input("Please choose A to Add, U to Update, V to View, X to Exit. ")
    user_choice=user_choice.upper()
    if user_choice == "V":
      if len(calendar.keys()) <1:
        print "Your calendar is empty"
      else:
        print calendar
    elif user_choice=="U":
      date = raw_input("What date?" )
      update = raw_input("Enter the update: ")
      calendar[date]=update
      print "The update has been successful"
      print calendar
    elif user_choice =="A":
      event = raw_input("Enter event: ")
      date= raw_input("Enter date (MM/DD/YYYY): ")
      year= date[6:]
      if len(date) >10 or int(year)>int(strftime("%Y")):
        print "The date you entered was invalid"
        try_again=raw_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 was successfully 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 was successfully deleted"
            print calendar
          else:
            print "An incorrect event was specified"
    elif user_choice == "X":
        start= False
    else:
        print "An invalid command was entered"
        start=False 
start_calendar()

#2

Hi @rubyblaster73281 ,

Inside the block headed by elif user_choice =="D":, you have this ...

event= raw_input = ("What event? ")

What is the purpose of that line?


#3

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