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 trialja5on
10,338 PointsDONE is the result
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
Python Development Techdegree Graduate 9,409 PointsHi 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!
ja5on
10,338 Pointsshopping_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)
ja5on
10,338 Pointsja5on
10,338 PointsOr could i call the list when done is entered, does that make sense? while True: new_item = input("> ")
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
Python Development Techdegree Graduate 9,409 PointsAsher Orr
Python Development Techdegree Graduate 9,409 PointsYou 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:
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?