Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ In this project, we'll build a basic calendar that the user will be able to interact with from the command line. The user should be able to choose to:
- View the calendar
- Add an event to the calendar
- Update an existing event
- Delete an existing event"""
- """
- Corrections made by codecademy advisor Alexander:
- corrected indentation, compare to your original code to see changes
- Syntax error in import statement, you originally had strtime instead of strftime (missing the F)
- Syntax error in elif statement: elif try_again == raw_input("Try Again? Y for Yes, N for No: "):
- You originally had one equal sign after elif try_again, remember that one equal sign is for
- assignment statements only.
- In that same elif statement, you forgot to end the elif conditional with a colon.
- Other than that, everything was good to go!
- -Alexander
- """
- from time import sleep, strftime
- USER_FIRST_NAME = "Gary"
- calendar = {}
- def welcome():
- print "Welcome to your calendar, " + USER_FIRST_NAME + "."
- print USER_FIRST_NAME + ", your calendar is opening now."
- sleep(1)
- print "Today is: " + strftime("%A %B/%d/%Y")
- print "The current time is: " + strftime("%H:%M:%S")
- print "What would you like to do, " + USER_FIRST_NAME
- 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 is empty."
- elif user_choice == "U":
- date = raw_input("What date?")
- update = raw_input("Enter the update:")
- calendar[date] = update
- print "Update successful."
- 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 "An invalid date was 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 "Addition successful."
- print calendar
- elif user_choice == "D":
- if len(calendar.keys()) < 1:
- print "Calendar empty."
- else:
- event = raw_input("Enter event: ")
- for date in calendar.keys():
- if event == calendar[date]:
- del calendar[date]
- print "Event successfully deleted."
- else:
- print "That event does not exist."
- elif 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
- start_calendar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement