Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Shopping List App Second Shopping List App

Gary Burner
Gary Burner
10,167 Points

Getting an error with minor change

Hi,

I had the script running without any errors before I added the append.(new_item) line into a function.

The script that worked was:

shopping_list = [] 

help_menu = """
    Type anything in to add to your list.
    Type "SHOW" to see your list and quit.
    Type "QUIT" to quit the program.
    Type "HELP" to see this help.
    """

print(help_menu)

#def new_item(user_input):
#   shopping_list.append(user_input)
#   print("You have added {}. List now has {} items.".format(user_input, len(shopping_list))

while True:
    user_input = input("> ")

    if user_input.upper() == "SHOW":
        print("Here is your list:")
        for item in shopping_list:
            print(item)
        continue

    if user_input.upper() == "QUIT":
        print("Here is your list:")
        for item in shopping_list:
            print(item)
        break

    if user_input.upper() == "HELP":
        print(help_menu)
        continue

    else:
        shopping_list.append(user_input)
        continue

The script that gets an error is:

shopping_list = [] 

help_menu = """
    Type anything in to add to your list.
    Type "SHOW" to see your list and quit.
    Type "QUIT" to quit the program.
    Type "HELP" to see this help.
    """

print(help_menu)

def new_item(user_input):
    shopping_list.append(user_input)
    print("You have added {}. List now has {} items.".format(user_input, len(shopping_list))

while True:
    user_input = input("> ")

    if user_input.upper() == "SHOW":
        print("Here is your list:")
        for item in shopping_list:
            print(item)
        continue

    if user_input.upper() == "QUIT":
        print("Here is your list:")
        for item in shopping_list:
            print(item)
        break

    if user_input.upper() == "HELP":
        print(help_menu)
        continue

    else:
        new_item(user_input)
        continue

Also the error that Im getting is:

line 16

while True:
    ^
Invalid Santax.

Im not sure why this change would cause an error on that line?

1 Answer

Mathew Tran
PLUS
Mathew Tran
Courses Plus Student 10,205 Points

You are missing a bracket in the new_item function, causing the next statement to have an issue.

def new_item(user_input):
    shopping_list.append(user_input)
    print("You have added {}. List now has {} items.".format(user_input, len(shopping_list)) # missing a bracket!!

Note:

  • it has 3 (
  • it has 2 )

Hope this helps!