Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. """This program creates a calendar that the user can interact with from the command line. It allows the user to: view the calendar, add an event to the calendar, update an existing event, delete an existing event"""
  2.  
  3. from time import sleep, strftime, localtime
  4. USER_NAME = "Odanga"
  5. calendar = {}
  6. def welcome():
  7. print("Welcome to MyCalendar %s") %(USER_NAME)
  8. print("MyCalendar is starting...")
  9. sleep(1)
  10. print("Today's date is: " + strftime("%A %B %d, %Y", localtime()))
  11. print("The time now is:" + strftime("%H:%M:%S", localtime()))
  12. sleep(1)
  13. print("What would you like to do?")
  14. def start_calendar():
  15. welcome()
  16. start = True
  17. while start:
  18. user_choice = raw_input("Enter 'A' to Add, 'U' to Update, 'V' to View, 'D' to Delete, 'X' to Exit:")
  19. user_choice = user_choice.upper()
  20. if user_choice == "V":
  21. if len(calendar.keys()) < 1:
  22. print("Calendar is empty right now")
  23. else:
  24. print(calendar)
  25. elif user_choice == "U":
  26. date = raw_input("What date?")
  27. update = raw_input("Enter the update:")
  28. calendar[date] = update
  29. print("Update was successful")
  30. print(calendar)
  31. elif user_choice == "A":
  32. event = raw_input("Enter event:")
  33. date = raw_input("Enter the date(MM/DD/YYYY):")
  34. if len(date) > 10 or int(date[6:]) < \
  35. int(strftime("%Y")):
  36. print("The date entered was invalid")
  37. try_again = raw_input("Try Again? Y for Yes, N for No: ")
  38. try_again = try_again.upper()
  39. if try_again == "Y":
  40. continue
  41. else:
  42. start = False
  43. else:
  44. calendar[date] = event
  45. print("The event was successfully added")
  46. print(calendar)
  47. elif user_choice == "D":
  48. if len(calendar.keys()) < 1:
  49. print("Calendar is empty")
  50. else:
  51. event = raw_input("What event?")
  52. for date in calendar.keys():
  53. if event == calendar[date]:
  54. del(calendar[date])
  55. print("The event was successfully deleted")
  56. print(calendar)
  57. else:
  58. print("An incorrect event was specified")
  59. elif user_choice == "X":
  60. start = False
  61. else:
  62. print("An invalid command was entered")
  63. start = False
  64. start_calendar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement