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

I can't get the print statement to work when calling add_to_list? Any suggestions?

Create a new empty list named shopping_list

shopping_list = []

Create a function named add_to_list that declares a parameter named item

# Add the item to the list

def add_to_list(item): shopping_list.append(item) print("Item has been added to the list! You currently have {} items in total".format(len(shopping_list))) # Notify the user that the item was added, and state the number of items in the list currently

def show_help(): print("What should we pick up at the store?") print(""" Enter 'DONE' to stop adding items. Enter 'HELP' for this help. """)

show_help() while True: new_item = input("> ")
if new_item =="DONE": break elif new_item == 'HELP': show_help() continue

Call add_to_list with new_item as an argumant

add_to_list(new_item)

Can you format your code using markdown?

1 Answer

Steven Parker
Steven Parker
243,266 Points

It's likely that you have an indentation issue, but it can't be identified in unformatted code. Use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:
Or watch this video on code formatting.

And an even better way to share workspace code is to make a snapshot of your workspace and post just the link to it here.

Thanks both - you were right in the fact it was a simple indentation issue. Thanks for the tip on how to format your code with asking questions as well, it was my first time asking a question in the community and was trying to get my head round making it work!

Steven Parker
Steven Parker
243,266 Points

Charlie Jones — Glad to help. You can mark a question solved by choosing a "best answer".
And happy holidays! :christmas_tree: