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 trialGary Burner
10,167 PointsGetting 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
Courses Plus Student 10,205 PointsYou 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!