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

done

I FALLOWED THIS ACCORDING TO THE VIDEO BUT HE DIDN'T MAKE A DONE DEF YET IT STILL WORKS I'M NOT SURE WHY CAN SOMEONE EXPLAIN THANKS

import os

shopping_list = []

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


def show_help():
    clear_screen()
    #this is gonna show that the user is gonna
    #in these cases since we have made a def for each this on this print list it will go but keep in mind that the things over here are are named simalar to what it says in the print list for example over here 
    print("what should we pick up at the store?")
    print("""    
Enter 'DONE' to stop adding items.
Enter 'HELP' to get help.
Enter 'SHOW' to see your list dude
Enter 'REMOVE' to delete a item fro your list 
""")


def add_to_list(item):
    show_list()
    if len(shopping_list):
        #new item like drek right here {}
        postition = input("where should i add the {}?\n"
                          "press ENTER to add to the end of the list\n"
                          "> ".format(item))
    #if theres nothing over there then its gonna be zero     
    else:
        position = 0 

    try:
        #the abs gives us the apsolote value if the number even if its gonna be a negitive its still gonna be a five or someting like that  
        position = abs(int(position))
    except ValueError: 
        position = None
    if position is not None:
        #what happens if its not none then we are gonna insert the item 
        shopping_list.insert(position-1, item)
    else:
        shopping_list.append(new_item)

    show_list()


def show_list(): 
    clear_screen()

    print("here's your list:")

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

    print("-"*10)    

def remove_from_list():
    show_list()
    what_to_remove = input("what would you like to remove from the list?\n> ")
    try:
        #meaning what ever you put in as remove to input function  
        shopping_list.remove(what_to_remove)
    except ValueError
        pass
    show_list()





show_help()
while True:
    new_item = input("> ")
    #when you put in done then the program is gonna exit since the break word is gonna make it drop out 
    if new_item.upper == 'DONE' or new_item.upper() == 'QUIT':
        break
    elif new_item.upper == "HELP':
        show_help()
        continue
    elif new_item.upper == 'SHOW':
        show_list()
        continue
    elif new_item.upper() == 'REMOVE':
        remove_from_list()

    else:     
        add_to_list(new_list)

show_list()

[MOD: added ```python formatting -cf]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,179 Points

Hi Shmuel, There were several typos that needed fixing before I could debug why 'DONE' was not working.

# fixed typos
    for item in shopping_list: # Fixed: renamed shpping_list to shopping_list

    add_to_list(new_item) # Fixed: renamed new_list to new_item

# fixed syntax errors
    except ValueError: # Fixed: added colon

    if new_item.upper() == 'DONE' or new_item.upper() == 'QUIT': # Fixed: added parens to .upper()

    elif new_item.upper() == 'HELP':  # Fixed: miss matching quotation marks in "Help'

    elif new_item.upper() == 'SHOW': # Fixed: added parens to .upper()

Why the 'DONE' wasn't working: The missing parens in new.item.upper is particularly hard to detect. Without the parens, it references the method upper but does not call it. Since it exists, it has a "truthy" value and will be syntactically correct, but will make the comparison always return false.

Post back if you have any more questions! Good luck!!