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

Shopping List: I did it with a function....I notice though that the professors method was a lot cleaner.

Is it better to parse everything into areas like the professor, in terms of convention or best practice? Here's what I did:

shoppingList= []
def listFunc(shoppingList):
    shoppingList = shoppingList
    item = input("What do you want to add to your list? " )
    if item == "DONE":
        return print(shoppingList)
    else:
        shoppingList.append(item)
        listFunc(shoppingList)

listFunc(shoppingList)

1 Answer

This is probably what my code would look like.

shopping_list = []
def list_func(shopping_list):
    while True:
        item = input("What do you want to add to your list? " )
        if item == "DONE":
            return shopping_list
        else:
            shopping_list.append(item)

list_func(shopping_list)

While your thinking about conventions, Python convention is to use snake casing for variables and function names. It won't break on camel casing, but it's kind of obvious that you are more used to another language.

Thanks!