Calendar project my code isnt working?


This is a picture of my code.
Along with the full code below.
For some reason the indentation is strange and causes me many errors, + when i copy and past it into text edit the print in lines in welcome() have larger indentations. Which is strange as it appears normal in my codecadamy code. The error i get is line 10: indentaion error: unexpected indent.
Another error I get is: elif user_ choice == "A":
indentation error: unexpected indent.
and u can see below in my code that i copy and pasted the elif does indeed have a strange indent that doesnt come up in codecadamy's code. So i am really confused.

"""This is a calender.."""
from time import strftime, sleep

username = "Paul"

calendar = {}

def welcome():
        print "Hi, " + username +", welcome to your personal calendar"
	print "Two seconds, your calendar is booting up"
	print "Today's date is: " + strftime("%A %B %d, %Y")
	print "The current time is: " + strftime("%H:%M:%S")
	print "What would you like to do?"

def start_calendar():
  start = True
  while start:
    user_choice = raw_input("A to Add, U to Update, V to view, D to delete, X to exit: ")
    if user_choice == "V":
      if len(calendar.keys()) > 0:
        print "Sorry, your calendar is empty"
        print calendar
    elif user_choice == "U":
      date = raw_input("What date?")
      update = raw_input("Enter the update: ")
      calendar[date] = update
      print calendar
  	elif user_choice == "A":
      event = raw_input("Enter event: ")
      date = raw_input(Enter date (MM/DD/YYYY))
      if len(date) > 10 or date[6:] < int(strftime(%Y)):
        print "Invalid date"
        try_again = raw_input("Try Again? Y for Yes, N for No: ")
        if try_again == "Y":
          start = False
        calendar[date] = event
        print username + ", your date has been added"
        print calendar
    elif user_choice == "D":
      if len(calendar.key()) == 0:
        print "Sorry " + username ", your calendar is empty, there is nothing to delete!"
        event = raw_input("What event?: ")
        for date in calendar.keys():
          if event == calendar[date]:
            print "Your event has successfully been deleted"
            print calendar
           	print "The event you entered did not correspond to an event in your calendar"
    elif user_choice == "X":
      start = False
      print "Invalid command"
      start = False


Indentations can become problematic when copying and pasting between different editors/IDEs. Pressing 'tab' will thus usually result in either 2 or 4 spaces (these seem to be the most popular lengths of indentation, as far as I know).

If you're finding problems with indentation, I'd recommend deleting the indented space and re-indenting it.

There are a few other minor errors in your code, but I'll let you (and the interpreter) try and catch them first once your indentation is fixed!


thanks i fixed the indentations and then the errors in the code thanks for answering tho


No problem! I decided that you'd be able to fix the other errors easily :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.