Calendar python Valid Date Not Working


I have a problem with my add function in my code. Here is my code of this part.

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:9]) < int(strftime("%Y"))):
    print "Invalid Date"
    try_again = raw_input("Try Again? Y for Yes, N for No: ")
    try_again = try_again.upper()
    if try_again == "Y":
      start == False
    calendar[date] = event
    print "The event was successfully added."
    print calendar

It seemed alright to me until I test it. When I enter the actual invalid date, the function work just fine, but after I enter the date that should be a valid one, the program still throws me an invalid message. I don’t know what I did wrong or how should I fix it.


Please post the full code so we can actually run the program and test the behavior.


Thank you for the fast response. I actually found my mistake. It was


It should be




because the last index of date’s length in this format is excluded. I was so focus on the index start counting from 0 and I overlooked the format function that it exclude the last number I wrote. In this case, the number 9 was excluded when the condition checked my input, therefore everything I enter will be invalid.