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 Basics (2015) Shopping List App Refactor

arifur rahman
arifur rahman
8,749 Points

shopping_list>refractor

i already have one suggestion that says there is problem in indentation. I tried that but I failed again

shopping_list.py
def main():


    show_help()

    # make a list to hold onto our items
    shopping_list = []

     while True:
        # ask for new items
        new_item = input("> ")

        # be able to quit the app
        if new_item == 'DONE':
            break
        elif new_item == 'HELP':
            show_help()
            continue
        elif new_item == 'SHOW':
            show_list(shopping_list)
            continue
        add_to_list(shopping_list, new_item)

    show_list(shopping_list)

3 Answers

Hi there,

Right before your 'while', do a single backspace - it's indented a little too far. If I copy-paste your code in and do that, it works.

Also, make sure you're keeping the code above line 22 also - you're probably just providing the relevant section, but just wanted to make sure.

arifur rahman
arifur rahman
8,749 Points

First of all...thanks...i tried that too...may it's a problem in the system or something like that.....

It could be - what error are you getting? The safest thing to do to avoid any indenting issues is just to reset the challenge, add the "def main():" line on line 22, then select everything below it and hit ctrl+] to space everything over. If that doesn't work, there could be something else going on.

Yushuai Cai
Yushuai Cai
564 Points

Hey two,

I found the reason!! Treehouse will not tolerate space between "def main" and "()".

So this is not accepted: def main ():

This is accepted: def main():

I think in Arifur Rahman's case it has nothing to do with indentation.

Get what I mean?

I get what you're saying, but in his example there, there isn't a space between main and the () - for me, his code up there works if I just do a single backspace on the 'while' line. What you mentioned is certainly something to look out for, though - I've had things like that come up on other questions for sure.

Yushuai Cai
Yushuai Cai
564 Points

@ Katie Wood

Oh I see, yeah to his case particularly, the issue is what you've pointed out. But I've found the space is strictly not tolerated in Treehouse. Anyway, thanks for commenting! :)

Of course! My comment was mostly for clarification purposes regarding the specific code block given. It's still a good thing to point out, and I'm glad you did - the intolerance for that space in challenges is important to know about, and is definitely something to be checked for when getting an unexpected syntax error in general. Thanks for the contribution!

arifur rahman
arifur rahman
8,749 Points

@ Katie Wood

Thanks a lot....my problem is solved now. you were right.....thanks again