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 trialAananya Vyas
20,157 Pointscant find the logic flaw please help
this is the challenge:
Same idea as the last one. 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".
def loopy(items):
for item in items: # use the singular of items as our iteration variable
if item.index(0) == "a":
continue
print(item) # reduce tab count so this isn't part of the if block
1 Answer
Wade Williams
24,476 PointsYou have an indent error in your code, your print statement needs to be outside of your if statement. And index() doesn't do what you think it does. You use index() to find something in a list like index("abc") and it will return the index of "abc" in the list. To get the value of an index you just use bracket notation like item[0].
All together now
def loopy(items):
for item in items:
if item[0] == "a":
continue
print(item)
Aananya Vyas
20,157 PointsAananya Vyas
20,157 Pointsthanks alot!