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 Introducing Lists Build an Application The Application

Youssef Moustahib
Youssef Moustahib
7,779 Points

This won't work?

I was just messing with the shopping list. Why won't this follow the rules set in place? It does not follow the conditions set in the "try" section. Just keeps appending.

shoplist = []
import sys

def helps():
    print("Enter DONE to finish your list and see it \n"
          "Enter SHOW to see your list \n"
         )
def clear():
    if os.name == 'nt':
        os.system('cls')
    else:
        os.system('clear')


while len(shoplist) < 20:

    try:
        item = input("> ").lower()
        if len(item) > 15 or len(item) <= 1:
            raise ValueError("That item is too long to spell or is too short")
            continue
        elif not item.isalpha():
            raise ValueError("Thats a number not an item..")
            continue


    except ValueError as err:
        ("Something has gone wrong. {}.".format(err))



    else:

        shoplist.append()
        print("shoplist")
else:
    print("you have reached the limit of 20 items")
    sys.exit()

1 Answer

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Youssef,

I noticed a few errors in your code:

("Something has gone wrong. {}.".format(err))

No print, so the string will be evaluated but never shown to the user

shoplist.append()

Doesn't append anything to shoplist

print("shoplist")

Just prints the string literal "shoplist" not the contents of the variable shoplist

Also, not an error but perhaps more restrictive than you expect or intend:

elif not item.isalpha():

Using isalpha() is too sensitive for many of the things you might put in your shopping list. For example, your test will not allow a person to put any of the following items in their shopping list:

  • band-aids
  • kit kats
  • 7up

Cheers

Alex