Advertisement
Guest User

Untitled

a guest
Jul 27th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. """ 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:
  2.  
  3. View the calendar
  4. Add an event to the calendar
  5. Update an existing event
  6. Delete an existing event"""
  7.  
  8. """
  9. Corrections made by codecademy advisor Alexander:
  10. corrected indentation, compare to your original code to see changes
  11.  
  12. Syntax error in import statement, you originally had strtime instead of strftime (missing the F)
  13. Syntax error in elif statement: elif try_again == raw_input("Try Again? Y for Yes, N for No: "):
  14. You originally had one equal sign after elif try_again, remember that one equal sign is for
  15. assignment statements only.
  16. In that same elif statement, you forgot to end the elif conditional with a colon.
  17.  
  18. Other than that, everything was good to go!
  19.  
  20. -Alexander
  21. """
  22. from time import sleep, strftime
  23.  
  24. USER_FIRST_NAME = "Gary"
  25.  
  26. calendar = {}
  27.  
  28. def welcome():
  29. print "Welcome to your calendar, " + USER_FIRST_NAME + "."
  30. print USER_FIRST_NAME + ", your calendar is opening now."
  31. sleep(1)
  32. print "Today is: " + strftime("%A %B/%d/%Y")
  33. print "The current time is: " + strftime("%H:%M:%S")
  34. print "What would you like to do, " + USER_FIRST_NAME
  35.  
  36. def start_calendar():
  37. welcome()
  38. start = True
  39. while start:
  40. user_choice = raw_input("A to Add, U to Update, V to View, D to Delete, X to Exit: ")
  41. user_choice = user_choice.upper()
  42. if user_choice == "V":
  43. if len(calendar.keys()) < 1:
  44. print "Calendar is empty."
  45. elif user_choice == "U":
  46. date = raw_input("What date?")
  47. update = raw_input("Enter the update:")
  48. calendar[date] = update
  49. print "Update successful."
  50. print calendar
  51. elif user_choice == "A":
  52. event = raw_input("Enter event: ")
  53. date = raw_input("Enter date (MM/DD/YYYY)")
  54. if (len(date) < 10) or int(date[6:]) < int(strftime("%Y")):
  55. print "An invalid date was entered."
  56. try_again = raw_input("Try Again? Y for Yes, N for No: ")
  57. try_again = try_again.upper()
  58. if try_again == "Y":
  59. continue
  60. else:
  61. start = False
  62. else:
  63. calendar[date] = event
  64. print "Addition successful."
  65. print calendar
  66. elif user_choice == "D":
  67. if len(calendar.keys()) < 1:
  68. print "Calendar empty."
  69. else:
  70. event = raw_input("Enter event: ")
  71. for date in calendar.keys():
  72. if event == calendar[date]:
  73. del calendar[date]
  74. print "Event successfully deleted."
  75. else:
  76. print "That event does not exist."
  77. elif try_again == raw_input("Try Again? Y for Yes, N for No: "):
  78. try_again = try_again.upper()
  79. if try_again == "Y":
  80. continue
  81. else:
  82. start = False
  83. start_calendar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement