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 trialGeorge Lugo
Python Web Development Techdegree Student 922 PointsWhat am i doing wrong for this problem
def loopy(items): if item in items: item[0]="a" continue else: print item
def loopy(items):
if item in items:
item[0]="a"
continue
else:
print item
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsThe check for the first character needs to be an if
-statement:
if item[0] == "a":
- "if" should be replace by "for" in the first statement to create the loop, with the above 'if` inside the loop
- Be sure to indent the
continue
andelse
block to align properly with the newif
-
print()
needs parens around arguments
Edit: updated to add for loop comment
Alexander Davison
65,469 Pointsdef loopy(iterable):
for item in iterable:
if item[0] == 'a':
continue
else:
print(item)
How this works:
- We loop through every single element in the list. You forgot to do this :)
- If the first letter in the item (we retrieve the first item by using item[0] because Python starts counting at 0) is the letter "a", we continue or "jump" to the next iteration.
- if the item's first letter is not "a", Python goes into the
else
clause and Python prints the item. Remember to use parentheses () arounditem
becauseprint
is also a function as well!
I hope this helps. ~Alex
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsGeorge Lugo also needs to use a
for
loop :)Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsThanks. Must have dropped that line when listing my changes from memory. I try not to post the completely corrected code or the full solution to encourage deeper learning. Post updated.