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 trialhuyen nguyen
850 Pointsmy code does not work
it said that my variable is not defined. I wonder why. Can I used 'try, except, else" command instead while loop? def loopy(items): items=[] while current in items: current[0] == "a" continue
def loopy(items):
items=[]
while current in items:
current[0] == "a"
continue
# Code goes here
2 Answers
Steven Parker
231,248 PointsYou have a few issues here:
- your first line replaces the argument with an empty list (don't do this!)
- you test a variable "current" in your while expression which was never defined
- did you perhaps intend to use a "for" loop instead of "while"?
- you compare the first character with "a" but without an "if" to control the flow
- the "continue" is not indented enough
- there's no "print" when the item matches the desired criteria
Ronald Tse
5,798 PointsREAD THE QUESTIONS CAREFULLY
Let me try to answer you (First time answering someone else questions)
you should not define the item as a empty list, i.e. items = []. Because it should be defined by the tester but not you. Make sure you know what is the function of this function.
you should use a for instead of a while, I recommend you to rewatch the video to understand the difference between while & if.
Make sure you have read the complete questions. The last part of the questions is to print out something (you should use an else to help you)