I think I may have found an error in the instructions for this project


#1

In step 42 of the Python project Command Line Calendar, we’re instructed to add an else block within the foreach loop, in the event that an invalid event was supplied.

# [...]
event = raw_input("Enter event to delete: ")

for date in calendar.keys():
  if event == calendar[date]:
    # delete the event
  else:
    # print error message regarding invalid event

The expected behaviour being that an error message would be printed only if no matches were found. But by placing it in the foreach loop as instructed, the error message is printed every iteration not matching the event, instead of only when no match was found in the whole dictionary.

One way to achieve the expected behaviour would be to have a boolean variable declared outside the foreach loop, initially set to false, and set it to true once a match is found, then check its state after the loop ends.

event = raw_input("Enter event to delete: ")
match_found = False

for date in calendar.keys():
  if event == calendar[date]:
    # delete the event
    match_found = True

if not match_found:
  print "Invalid event: {:s}".format(event)

It’s possible I misunderstood the instructions, but just in case… :slight_smile:


#2

Hi @chris-1101 ,

Yes, the instructions are faulty with regard to the issue that you have raised. See this thread: Command Line Calendar How can I fix this?.


#3

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