Cant figure out what ive done wrong with my code


#1



I am getting syntax errors all over the place, ive tried to indent code both ways knowing its 4 spaces needed for indentation.


I was expecting it to work, since ive been trying to debug the program as i go.


""" Now we are going to make a command line calendar."""
from time import sleep, strftime
username = "Stian"

calendar = {}

def welcome():
  	print "Welcome" + username
  	print "Calendar is opening"
  	sleep(1)
  	print "Today is: " + strftime("%A %B %d, %Y")
  	print "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()) < 1:
        				print "The calendar is empty"
      			else:
        				print calendar
   			elif user_choice == "U":
      			date = raw_input("What date?: ")
      			update = raw_input("Enter the update: ")
      			calendar.update(date, update)
      			print "Update successful!"
      			print calendar
     		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:10]) < int(strftime("%Y")):
        				print "Invalid date entered"
        				try_again = raw_input("Try Again? Y for Yes, N for No: ")
        				try_again.uppercase()
        				if try_again == "Y":
            					continue
        				else:
          			    start = False
						else:
        				calendar[date] = event
       					print "Event successfully added.."
          			print calendar
          
    		elif user_choice == "D":
      			if calendar.keys() < 1:
              	print "Calendar is empty"
        
      			else:
        				event = raw_input("What event?: ")
        				for date in calendar.keys():
          					if event == calendar[date]:
            						del calendar[date]
            						print "Successfully deleted"
            						print calendar
          					else:
            						print "Incorrect event specified"
     		elif user_choice == "X":
      			start = False
    		else:
      			print "Invalid command given"
      			break


#2

I see it now! indentation is way off, the learning platform seems to be off in how it shows the indentation.

edit2:
okay, so i fixed the indentation. But now its giving me syntax errors on my firste elif statement.


#3

The code you posted is mixing tabs and spaces. Use only spaces or only tabs (4 spaces are preferred)


#4

So does the code look ok besides that ?


#5

If you want someone to judge your code then fix up the things you already know are bad


#6

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