Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
ronald brown
2,867 Pointssyntax error on my elif statement on shopping second app
So im almost finished with this the video for shopping list the second app and i get a elif syntax error for an elif statement. I compare the code to the teachers code and Im not seeing the difference can anyone help?
2 Answers
Jerehme Gayle
5,206 PointsHello Ronald,
The only things I can see is that the continue in your second elif: statement needs to be indented And you need an else: statement at the end right before you call add_to_list then tab over_add_to list. Also you should be using .upper() on new_item in your comparisons if you are looking for DONE, HELP, SHOW. Otherwise, if the user enters the lowercase version of done, help, show the correct function will not run. It is best practice to either use .lower() and compare to the lowercase of what you're looking for or use .upper() and compare to the uppercase of what you're looking for. I hope this helps
Below is your code with the changes mentioned
if new_item.upper() == 'DONE':
break
elif new_item.upper() == 'HELP':
show_help()
continue
elif new_item.upper() == 'SHOW':
show_list()
continue
else:
add_to_list(new_item)
show_list()
Happy coding
ronald brown
2,867 Pointsthat actually helped (both), thanks
ronald brown
2,867 Pointsronald brown
2,867 Pointsmake a list that will hold on to our items
shopping_list = ['milk', 'butter', 'eggs']
def show_help(): #print out instuctions print("What should we pick up at the store?") print("""" Enter 'DONE' to stop adding items. Enter 'HELP' for this help. Enter 'SHOW' to see you current list. """) def show_list(): #print out the list print("Here's your list:")
def add_to_list(new_item): #add new items to our list shopping_list.append(new_item) print("Added{}. List now has {} items.".format(new_items, len(shopping_list)))
while True: #ask for new items new_item = input("> ")
show_list()
this is what i got i tried to add a snapshot of my workplace but i dont know how to do it if anyone can teach me that i would greatly appreciate it.