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 Python Basics (2015) Shopping List App Shopping List Introduction

First Challenge Question, Shopping List

I know the first Shopping List Challenge is not meant to be that hard, but I'm stuck. I've tried a few different things...this is what I think is closest to correct. Any help would be appreciated...I haven't asked for help yet. Thanks.

def loopy(items): for item in items: print(item) if item.UPPER() == 'STOP': break loopy()

Sorry...I didn't realize the code would print like that.

7 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Well as I see it there are a couple of problems here. First it's going to print out everything... including STOP because you have the print before the the conditional to check if it was STOP. Also, there's no need to tell it what to break. It knows it's breaking out of that function. Take a look at my solution

def loopy(items):
    # Code goes here
    for thing in items:
      if thing == "STOP":
        break
      else:
        print(thing)

Here we start through our iterable and if the thing is STOP then we break immediately without printing. Otherwise, we print it. Yours is backwards. You print the thing, then ask if it was STOP. Which means that if it was STOP it will print STOP and then exit. Hope this helps!

yea! I forgot to print "thing" inside of "if" statement (my "print" was before "if"). If I wouldn't do that, it will never end. Thanks!

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Evan Genter I just ran your code through the challenge and it worked fine for me. That being said, your code will not pass the first step... only the second step. Pay close attention to the instructions in the first step and make it match what it's asking for... in the order it's asking for it.

Maksym Filippov
Maksym Filippov
3,986 Points

Im really stuck on the first challenge, I copied and pasted your code Jennifer and does not let me through, please help

Thanks for getting back so fast! I just entered in exactly what you posted (I added the loopy() at the end) and it didn't work. I'm your answer is right...this isn't a difficult challenge. I'm not sure what's going on. Maybe I'm indenting something wrong? Frustrating. Thanks again for the quick reply.

Is there I way I can post screenshots in a reply?

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

That's really odd. Not to sound silly here, but you're erasing everything and copy/pasting my code, correct? Because when I do that.. it passes.

def loopy(items): # Code goes here for thing in items: if thing == "STOP": break else: print(thing) loopy()

Sorry. Meant to include with previous.

Just got it..Thanks so much for the help, Jennifer! Screwed up an indent, and I thought I needed the callback...

Thanks again.

Stuck again. I don't plan on making a habit of asking every time I'm stuck...maybe just a hint? This is the Random Item question...

import random def random_item(iterable): num = random.int(0, len(iterable-1)) return(iterable[num]) def random_item('Treehouse')

Thanks fo any advice

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

cj thompson I believe the solution you're looking for, I posted just a few hours ago for someone else. Take a look at this https://teamtreehouse.com/community/i-dont-understand-24

Otherwise, you can link the challenge you're working on :)

But you're doing really well! In fact, I think your problem may be that you should just leave off the last line and it might work (barring any indentation errors).

Jennifer, you're the best! The solution is quite a bit easier than what I was doing. I think I only have a few more challenges to go in Python Basics...looks I'll need to go back and review some things. Thanks again.