Calendar project my code isnt working?


#1




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"
	sleep(1)
	print "Today's date is: " + strftime("%A %B %d, %Y")
	print "The current time is: " + strftime("%H:%M:%S")
	sleep(1)
	print "What would you like to do?"

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.upper()
    if user_choice == "V":
      if len(calendar.keys()) > 0:
        print "Sorry, your calendar is empty"
      else:
        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: ")
        try_again.upper()
        if try_again == "Y":
          continue
        else:
          start = False
      else:
        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!"
      else:
        event = raw_input("What event?: ")
        for date in calendar.keys():
          if event == calendar[date]:
            del(calendar[date])
            print "Your event has successfully been deleted"
            print calendar
          else:
           	print "The event you entered did not correspond to an event in your calendar"
    elif user_choice == "X":
      start = False
    else:
      print "Invalid command"
      start = False
start_calendar()


#2

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!


#3

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


#4

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


#5

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