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_list3.py problem

Why doesn't my While loop work? Does not break when 'QUIT' is applied. It just adds it to the end of list and i cannot exit() out of the program. import os

shopping_list= []

def clear_screen(): os.system("cls" if os.name == "nt" else "clear")

def show_help(): clear_screen() print("what we should pick up at the store") print(""" Enter 'Done' to stop adding items. Enter 'Help' to get help Enter 'Show' to see current list. Enter 'Remove' to delete an item from your list """)

def add_to_list(new_item): show_list() if len(shopping_list): position = input("Where should I add {}?\n" "Press ENTER to add to the end of list" "> ".format(new_item)) else: position = 0

try:
    position = abs(int(position))
except ValueError:
    position = None
if position is not None:
    shopping_list.insert(position-1, new_item)
else:
    shopping_list.append(new_item)
show_list()

def show_list(): clear_screen()

print("Here's your list!")

index = 1
for item in shopping_list:
    print("{}. {}".format(index, item))
    index += 1

print("-" * 10)

def remove_item(): show_list() what_to_remove = input("What should we remove?\n> ") try: shopping_list.remove(what_to_remove) except ValueError: pass show_list()

show_help()

while True: new_item = input("- ")

ask for new items

if new_item.upper == 'Done' or new_item.upper == 'QUIT':
    break
elif new_item.upper == 'Help':
    show_help()
    continue
elif new_item.upper == 'Remove':
    remove_item()

elif new_item.upper == 'Show':
    show_list()
    continue
else:
     add_to_list(new_item)

show_list()

print("Here's your list")

for item in shopping_list: print(item)

not sure how snapshot works obviously haha https://w.trhou.se/65x26wzf5h

2 Answers

Hi! upper is a method. Since you are calling new_input.upper, this will return a method, however, if you call the method it will return a string like this: new_input.upper(). Notice the parentheses. I hope this helps.

hmmm. added the parenthesis but still doesn't do anything. Just continues adding it to my list

You have a lot of upper functions. Be sure to add parentheses to all of them. I've tried doing that and it works. It quits as expected.