Can't get my Calendar to work at all


#1



Since the only two things you can do at the start are View (which should give you a 'no entry' error) and Add, I tried them both and I get different errors for each one.

When I try to Add, I get asked the event and the date and when I input the date I get
Traceback (most recent call last):
File "Calendar.py", line 68, in
start_calendar()
File "Calendar.py", line 47, in start_calendar
calendar[date] = event
TypeError: list indices must be integers, not str

When I try to View I get:
Traceback (most recent call last):
File "Calendar.py", line 68, in
start_calendar()
File "Calendar.py", line 25, in start_calendar
if len(calendar.keys()) < 1:
AttributeError: 'list' object has no attribute 'keys'


I do not know what the issue is. I looked at all the hints and my code looks like it does in the hints and I just cannot get this to work.


from time import sleep, strftime

user = 'Chris'
calendar = []
def welcome():
  print "Welcome to your calendar, " + user + "."
  print "Opening your calendar..."
  sleep(1)
  print "Today is: " + strftime("%A %B %d, %Y")
  print "The time is: " + strftime("%I:%M:%S")
  sleep(1)
  print "What would you like to do?"

def start_calendar():
  welcome()
  start = True
  while start == True:
		user_choice = raw_input("A to Add, U to Update, V to View, D to Delete, X to Exit: ")
		user_choice = user_choice.upper()
		if user_choice == "V":
			if len(calendar.keys()) < 1:
				print "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 "You have updated the calendar"
			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:]) < int(strftime("%Y"))):
				print "An invalid date was entered."
				try_again = raw_input("Try again? Y for Yes, N for No: ")
				try_again = try_again.upper()
				if try_again == 'Y':
					continue
				else:
					start = False
			else:
				calendar[date] = event
				print "You have added to the calendar"
				print calendar 
		elif user_choice == 'D':
			if len(calendar.keys()) < 1:
				print "Calendar is empty"
			else:
				event = raw_input("What event? ")
				for date in calendar.keys():
					if event == calendar[date]:
 						del calendare[date]
						print "You have deleted the event from the calendar"
						print calendar 
 					else:
						print "An invalid event was entered"
		elif user_choice == 'X':
			start = False
		else:
			print 'An invalid command was entered'
			start = False


#2

Have you had a look at the error messages that you are getting? There's quite a lot of information there about what went wrong that you can follow up on and compare to your intentions


#3

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