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 trialyousef alharthi
551 Pointsa problem with show_list
hello guys, I have a problem that the program is working but doesnt return me the list. I mean when I type SHOW or DONE it show me an error message. can you please help me with it
shopping_list = []
def show_help():
print("what should we pick at the supermarke?")
print("enter 'DONE' to stop, Enter 'HELP' for this help, Enter 'SHOW' to see you list")
def add_to_list(item):
shopping_list.append(item)
print("added! list has {} items.".format(len(shopping_list)))
def show_list():
print("Here is your list:")
for items in shopping_list:
print(item)
show_help()
while True:
new_item = input("> ")
if new_item == 'DONE':
break
elif new_item == 'HELP':
show_help()
continue
elif new_item == 'SHOW':
show_list()
continue
add_to_list(new_item)
continue
show_list()
1 Answer
Max Hirsh
16,773 PointsHey Yousef, it's kind of difficult to tell exactly what is happening without seeing the error message. From what you pasted though, it looks like you are writing the definition of each method/function on a single line. Remember to keep new statements on different lines with the proper indentation like so:
def add_to_list(item):
shopping_list.append(item)
print("added! list has {} items.".format(len(shopping_list)))
Let me know if restructuring your code like this helps!
yousef alharthi
551 PointsI could do it ! thanks mh42
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsAndreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi yousef
I have formatted your post so your code is more readable. See Markdown Cheatsheet below for instructions on how to format your posts.