A,U,D, X raw input not working. Cant figure it out!


#1



https://www.codecademy.com/en/courses/python-ext/projects/calendar


I can not figure out why my it keeps defaulting to the final else statement. When I input A,U,D or X nothing happens


I expected it to add, update etc. instead of returning "Invalid command "


"""Calendar

Author: James"""

from time import sleep, strftime

USER_NAME = "James"

calendar = {}

def welcome():
  print "Welcome to the Calendar %s" % USER_NAME
  print "the calendar is opening"
  sleep(1)
  print "Today is " + strftime("%A, %B, %d, %Y")
  print strftime("%I:%M:%S")
  print "What would you like to do?"

def start_calendar():
  welcome()
  start = True
  while start:
    user_choice = 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()) < 1:
        print "Calendar empty."
      else:
        print calendar
    elif user_choice == "U":
      date = raw_input("What date?")
      update = raw_input("Enter the update: ")
      calendar[date] = update
      print "Update succesful"
      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 entered"
        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 "The event was added to the calendar"
        print calendar
    elif user_choice == "D":
      if len(calendar.keys()) < 1:
        print "Calendar empty"
      else:
        event = raw_input("What event?")
        for date in calendar.keys():
          if event == calendar[date]:
            del calendar[date]
            print "Event succesfully deleted"
            print calendar
          else:
            "Incorrect event was specified"
    elif user_choice == "X":
      start = False
    else: 
      print "Invalid command "
      break
start_calendar()


#2

Recall that upper is a string method, upper().


#3

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