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 trialJiwon Kim
999 PointsShopping_list_2.py 1. SHOW does not show my current list. 2. print(.... format(new_item, len( ))) not working
- SHOW does not show my current list.
- print(.... format(new_item, len( ))) not working
- DONE does not recall the completed list.
This is a link (https://w.trhou.se/wggf4lwjjb)
shopping_list = []
def show_help():
#print out instructions on how to use the app
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 your current list.""")
def show_list():
#print out the list
print("Here is your list:")
for item in shopping_list:
print(item)
def add_to_list(new_item):
#add new items to our list
shopping_list.append(new_item)
print("Added {}. List now has {} item.".format(new_item, len(shopping_list)))
show_help()
#while loop to run forever
#ask for new items
#be able to quit the app
while True:
new_item = input("> ")
if new_item == 'DONE':
break
elif new_item == 'HELP':
show_help()
continue
elif new_item == 'SHOW':
show_list()
continue
```
2 Answers
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Jiwon
The reason its not working is because you are not actually adding anything to the shopping_list. You have created an add_to_list function but you dont seem to be calling it.
shopping_list = []
def show_help():
#print out instructions on how to use the app
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 your current list.""")
def show_list():
#print out the list
print("Here is your list:")
for item in shopping_list:
print(item)
def add_to_list(new_item):
#add new items to our list
shopping_list.append(new_item)
print("Added {}. List now has {} item.".format(new_item, len(shopping_list)))
show_help()
#while loop to run forever
#ask for new items
#be able to quit the app
while True:
new_item = input("> ")
if new_item == 'DONE':
break
elif new_item == 'HELP':
show_help()
continue
elif new_item == 'SHOW':
show_list()
continue
# added this else statement. If any of the above conditions are not met, it means user wants to add to the list
else:
add_to_list(new_item)
continue
Wu Ray
2,359 PointsI see you have created adding_list function but seems you never put it into your while loop which means you did't call it. Like Andrea had mentioned you have to put it into your loop so python know you want to add it.