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 (Retired) Lists Redux Shopping List Take Three

'SHOW' displays nothing

(I wasn't sure how to format code to be indented properly/look okay on the forums so I'm including a screenshot of my code instead.)

I have copied the code from this video line for line into my text editor and when I run it and type 'SHOW' nothing gets displayed. I know a similar question was asked previously-- I tried implementing that code and it threw an error when I tried to call 'SHOW.'

Here is my code: https://w.trhou.se/zt90k1lofz

I've reviewed it several times and cannot figure out what I'm doing incorrectly. I have noticed the code works fine if I remove everything from the 'else' statement apart from the line that appends a new item to the list, so I'm guessing that's where my problem is, I just can't seem to find it.

Any insight would be greatly appreciated!

2 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

I forked your Workspace and noticed that the indentation for the else statement at the end was lined up under the for loop. What happens, as far as I could tell, is that after you entered a list and just hit enter (meaning don't set an index) then a list would not be created. If you set an index for the list it would double the list regardless of the number entered.

After I fixed the indentation the program ran as expected.

Here is my output after lining up the else statement with the if above it:

treehouse:~/workspace$ python shopping_list.py                                                                 
What do you want to shop for?                                                                                  

Separate each item with a comma.                                                                               
Type DONE to quit, SHOW to see the current list, and HELP to see this message.                                 
> A, B                                                                                                         
Add item at certain spot? Press enter for end of list, or give me a number. Currently 0 items in the list0     
> SHOW                                                                                                         
1: B                                                                                                           
2: A                                                                                                           
> C                                                                                                            
Add item at certain spot? Press enter for end of list, or give me a number. Currently 2 items in the list2     
> SHOW                                                                                                         
1: B                                                                                                           
2: C                                                                                                           
3: A                                                                                                           
> DONE                                                                                                         

Here is your list:                                                                                             
1: B                                                                                                           
2: C                                                                                                           
3: A                                                                                                           
treehouse:~/workspace$

Aha! That did it, thank you so much! It really helps to have someone 'proofread' your code (though I should probably wear my glasses while coding as well, maybe I would've spotted that).

Sean T. Unwin
Sean T. Unwin
28,690 Points

Heheh. :-p

True. Another set of eyes sometimes helps a ton.