Why doesn't my calendar exit?

I am working on this excercise:

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

This is my code:

from time import sleep, strftime
USER_NAME = "Clarinda"
calendar = {}

def welcome():
  print "Welcome, " + USER_NAME + "."
  print "Calender is opening.."
  sleep(1)
  print "Current date: " + strftime("%A %B %d, %Y")
  print "Current time: " + strftime("%H:%M:%S")
  sleep(1)
  print "What would you like to do?"

def start_calendar():
  welcome()
  start = True
  while True:
    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 "The 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 "Update is 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 "This is a invalid date."
        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 succesfully added."
        print calendar
    elif user_choice == 'D':
      if len(calendar.keys()) < 1:
        print "Calendar is empty."
      else:
        event = raw_input("What event? ")
        for date in calendar.keys():
          if event == calendar[date]:
            del calendar[date]
            print "Event removed succesfully."
            print calendar
          else: 
            print "incorrect event was specified."
            try_again = raw_input ("Try again? Y/N")
            try_again = try_again.upper()
            if try_again == "Y":
              continue
    elif user_choice == 'X':
      start = False
    else:
      print "Invalid command."
      start = False
start_calendar()      

When I give a wrong choice or choose “X”, the calender won’t exit.
Can somebody help me see what I did do wrong?

while True will run forever. Use the flag you’ve created: try while start

1 Like

Thank you!

Can’t believe I didn’t see that…