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 Python Collections (2016, retired 2019) Lists Shopping List Take Three

gabrielle moran
gabrielle moran
1,985 Points

Why does this print statement not execute after the changes?

```def add_to_list(item): show_list() if shopping_list: position = input("Where do you want {}?\n" "Press ENTER to add it to the end\n" ">> ".format(item)) else: position = 0

try:
    position = abs(int(position))
except ValueError:
    position = None
if position is not None:
    shopping_list.insert(position-1, item)
else:
    shopping_list.append(item)

print("{} added! List has {}items.".format(item,len(shopping_list)))

show_list()```

I get why Kenneth removes this print statement (because it is not executing after all the changes to the add_to_list function), but why doesn't it execute? It is at the end except for the show_list() which does execute

2 Answers

on the last line each time u add or insert an item u call show_list() in the end which prints the updated list every time. u don’t see the print command in the end because u call the show_list function which update the list. the important thing to know is that the print command get executed but because of the function u don’t see it

gabrielle moran
gabrielle moran
1,985 Points

Yeah, that explanation makes sense, thanks bot.net