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 trialJohn Conner
Courses Plus Student 1,360 PointsWrapping my head around script format; what is the general rule with ":" and block text and indentions.
Is this the error that I am experiencing, one of formatting.? Or is it a bigger issue with functions?
def loopy(items):
for item in items:
if item == "STOP"
break:
else print(item)
1 Answer
Marek Zakrzewski
2,920 PointsHi,
Your code doesn't work due to an issue in the formatting. You've used ":" incorrectly. You should use it every time you declare a function, and use a conditional statement. For example:
def your_function():
#your code goes here
if x == y:
#your code goes here
Also keep in mind, that using the : also means that you need to use indentation, which also is wrong at two places in your code. You use break on the same level of indentation as your if statement - I suppose it didn't get indented automatically, since your if statement is missing a ':' there. Also your else statement is indented on the same level as you declare your function, which is also incorrect. It should be the same level of indentation as your if statement. The last thing is, your else statement is also missing a ':' and then the correct indentation. Writing it like this would only cause syntax error.
Your code then should look like this:
def loopy(items):
for item in items:
if item == "STOP":
break:
else:
print(item)
Feel free to poke me if you have any more questions.
Kind regards,
Marek
John Conner
Courses Plus Student 1,360 PointsJohn Conner
Courses Plus Student 1,360 PointsI certainly appreciate the wheres and why and possible the because of's. who knew such a groovy language could such a grammar snob. HAHAHA