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 trialArash Emadi
10,002 PointsStuck in Continue challenge
I'm stuck on this challenge and my code doesn't work.
The challenge says this. My loopy function needs to skip an item this time, though. Loop through each item in items again. If the character at index 0 of the current item is the letter "a", continue to the next one. Otherwise, print out the current member. Example: ["abc", "xyz"] will just print "xyz".
Thanks.
def loopy(items):
# Code goes here
for item in items:
print(item)
if item == "a":
break
print(item)
1 Answer
Steven Parker
231,236 PointsHere's a few hints:
- the entire item doesn't need to be "a", you should only match on the first letter
- don't break the loop on a match, but continue to the next item
- the "if" needs to be indented more to put it inside the loop
- there should only be one print statement
Arash Emadi
10,002 PointsArash Emadi
10,002 Pointsthanks for the response.
I changed the lower part to this but still it doesn't pass. it just says try again.
Steven Parker
231,236 PointsSteven Parker
231,236 PointsCloser, but you need to apply the index to the item, and you still want to compare it with "a":
if item[0] == "a":
Also, the "if" and "break" need to be indented more to put them inside the loop, and there should only be one "print" statement (after the "if").
Arash Emadi
10,002 PointsArash Emadi
10,002 PointsThank you so much for your help.
i did all of that and i also did indented the if in the loop but now it's says the right items aren't being printed and there is also only one print after the if
Steven Parker
231,236 PointsSteven Parker
231,236 PointsPlease show the whole code as it is now.
Arash Emadi
10,002 PointsArash Emadi
10,002 Pointsok it's like this now
Arash Emadi
10,002 PointsArash Emadi
10,002 PointsThank you for your help but i figured it out
i could've just used this.
if item[0] != 'a':
Steven Parker
231,236 PointsSteven Parker
231,236 PointsActually, that would test for the wrong condition and not be correct. But it could work if you used it to control the "print" statement instead of the "continue".
The actual issues with that last version are: