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 trialBrett Burky
3,895 PointsShopping List Redux
I am trying to copy verbatim what Kenneth is doing in this video. I am curious if there is a spacing issue that might be why this doesn't work but I can't seem to find it.
http://cl.ly/image/21120S3S2w2e this is a screen shot of my exact code...which looks a lot like his code.
This is what it is saying that I am doing wrong: http://cl.ly/image/1w220L3F2r1k Any help is appreciated.
2 Answers
Juan Martin
14,335 PointsHello Brett, I saw 2 errors on the code you have showed on the image:
- On line 8, instead of shopping.list.append(item) it should be shopping_list.append(item)
- From line 22 to 26 there's an indentation error, the "elif" block, "add_to_list(new_item)" and "continue" must have the same indentation as all the code before it (I mean, the same indentation as the "if" block for example).
With this errors fixed, the code should be like this:
shopping_list = []
def show_help():
print("What should we pick up at the store?")
print("Enter DONE to stop. Enter HELP for help.")
def add_to_list(item):
shopping_list.append(item)
print("Added! List has {} items.".format(len(shopping_list)))
def show_list():
print("Here's your list:")
for item in shopping_list:
print(item)
show_help()
while True:
new_item = input("> ")
if new_item == 'DONE':
break
elif new_item == 'HELP':
show_help()
continue
add_to_list(new_item)
continue
show_list()
Hope this helps :)
Kenneth Love
Treehouse Guest TeacherYour elif
and add_to_list
should be indented the same amount as your if
.