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!
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
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()
Jennifer NordellTreehouse 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!
Maksym Filippov3,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?
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...
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, 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.