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 list question

I just did the shopping list in python, but with the if and elif statements,they do not work, I type DONE or HELP for example and it writes if i want to add them to the list instead of using the function and then continuing this is my code can someone please help me?

import os

shopping_list=[]
def show():
  clear() 
  index= 1
  print("heres your list")
  for item in shopping_list:
    print("{},{}".format(index,item))
    index+=1



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

def help():
    clear()
    print("what would you like to pick up")
    print("enter 'DONE' to stop adding items")
    print("Enter 'HELP' to see help")
    print("Enter 'SHOW' to see your list")

def addtolist(item):
  show()
  if len(shopping_list):
    posistion = input("where should I add {}?\n"
                      "Press Enter to add to the end of the list\n"
                      "> ".format(item))
  else:
        posistion = 0

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


help()
while True:
  item = input("Enter an item you would like: ")
  if item.upper =='DONE' or item.upper()=='QUIT':
      break
  elif item.upper == 'HELP':
      help()
      continue
  elif item.upper =='SHOW':
      show()
      continue
  else:    
      addtolist(item)


print("You have " + ", ".join(shopping_list)+" on the list")```

1 Answer

To uppercase the input you need to add parenthesis to your upper methods.

item.upper() == "HELP"

# not

item.upper == "HELP"