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

Python Introducing Lists Build an Application Add Items

DONE is the result

https://w.trhou.se/6hhguqz2nq

My Input.
eggs
ham
cheese

My result.
DONE
Added! List has items.

f string not working but i know why.
I would like to see a list but why am i getting done as the result?

2 Answers

Asher Orr
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Asher Orr
Python Development Techdegree Graduate 9,410 Points

Hi Jas0n!

Here's the problem: you're calling the add_to_list function only if "DONE" is the user's input.

To see what I mean, check out the comments:

show_help()
#display message

while True:
    new_item = input("> ")
    # ask for user input

    if new_item == "DONE":
    # if the input is "DONE," break out of the loop.
    # then call the add_to_list function.
        break
    elif new_item == "HELP":
    # if the input is "HELP," display the show_help message and continue the loop.
        show_help()
        continue

add_to_list(new_item)
#when your while loop breaks, call this function.

The add_to_list function is called when the loop breaks. The loop breaks only when new_item == "DONE".

To fix the problem, adjust your code to to call that function if something other than "DONE" is entered.

I hope this helps. Let me know if you have further questions!

Or could i call the list when done is entered, does that make sense? while True: new_item = input("> ")

if new_item == "DONE":
    break
elif new_item == "END":
    print(add_to_list(new_item))
elif new_item == "HELP":
    show_help()
    continue

I did the above but still no luck Think im lost

I'm tying to print the list upon DONE I think this program is above my knowledge

Asher Orr
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Asher Orr
Python Development Techdegree Graduate 9,410 Points

You could call the list when "DONE" is entered. In the new code, you're printing the add_to_list function if the user's input is "END".

Compare it to this code:

while True:
    new_item = input("> ")
    #ask for user's input
    if new_item == "DONE":
        break
    #if input is "DONE", break out of the loop.
    elif new_item == "HELP":
        show_help()
        continue
    #but if the input is "HELP", call show_help function and repeat the loop.
    else:
        add_to_list(new_item)
    #if input isn't DONE or HELP, call the add_to_list function! 

To display all the contents in the list, you could create a show_list function and add it to your script.

Does this make sense?

shopping_list = []

def add_to_list(item):
shopping_list.append(item)
print("Added! List has items.".format(len(shopping_list)))

def show_help():
print("What should we pick up at the store?")
print("""
Enter 'DONE' to stop adding items.
Enter 'HELP' for this help.
""")

show_help()

while True:
new_item = input("> ")
### ### ### ### Below i added a new function to show the list is this what you mean.
if new_item == "DONE":
def show_list():
print(shopping_list)
show_list()
break

elif new_item == "HELP":                                                                                                                       
       show_help()                                                                                                                                             
       continue                                                                                                                                            

else:
       add_to_list(new_item)