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 trialLaknath Gunathilake
1,860 PointsSHOW not working in shopping list app 3
when I type SHOW, it doesnt show the items I have added to the list
<p>
shopping_list=[]
def show_help():
print("\nSeperate each item with a comma.")
print ("Type DONE to quit. SHOW to see the current list,and HELP to get this message.")
def show_list():
count=1
for item in shopping_list:
print("{}:{}".format(count,item))
count+=1
print("Give me a list of things you want to shop for.")
show_help()
while True:
new_stuff=input(">")
if new_stuff =='DONE':
print("\nHere's your list:")
show_list()
break
elif new_stuff=='HELP':
show_help()
continue
elif new_stuff =='SHOW':
show_list()
continue
new_list=new_stuff.split(",")
index=input("Add this at a certain spot? press enter for the end of the list, "
"or give me a number.Currently {} items in the list".format(
len(shopping_list)))
if index:
spot=int(index)-1
for item in new_list:
shopping_list.inster(spot,item.strip())
spot+=1
else:
for item in new_list:
shopping_list.append(item.strip())
<\p>
,,,
2 Answers
Seth Kroger
56,413 PointsLooks like you have a small indentation error near the end of the script where you add items to the list.
if index:
spot=int(index)-1
for item in new_list:
shopping_list.inster(spot,item.strip())
spot+=1
else: # <-----This is on the same level as the for loop, so it's still inside the if block
for item in new_list:
shopping_list.append(item.strip())
# instead should be:
else:
for item in new_list:
shopping_list.append(item.strip())
Michael De La Cruz
10,800 PointsI think the error is that he doesn't have an else statement after the last elif
Nathan Brenner
35,844 PointsI had that earlier, and it threw a syntax error. You can get away with ending a conditional statements in javascript with else if
, but it looks like python doesn't. Either way, that wouldn't have caused the bug Laknath described.