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 trialIAN WOOD
1,336 PointsOdd/Even "task 1 no longer passing" ???
I've run into this before, on other challenges, and it's really frustrating - not in a "I can't understand this" way, in a more fundamental "This program doesn't seem to work as a teaching method" way.
What I mean:
- Task One, passes.
- Task Two, passes.
- Task Three = Oops! It looks like task One is no longer passing!
At this point, my options are to Get Help or Go to Task One. If I go back to task one, I see that it hasn't changed, so I get:
- Task One, passes.
- Task Two, passes.
- Task Three = Oops! It looks like task One is no longer passing!
It's an endless loop, with no new information provided, and no way to troubleshoot the code unless I take it somewhere else, like Python Tutor.
Is that the point...? To force me to figure it out outside of Treehouse...?
Which I'm now doing - I know the code doesn't work. But I wanted to bring this up here - there just doesn't seem to be a way to figure out //why// it doesn't work using the provided tools. here.
import random
start = 5
def even_odd(num):
# If % 2 is 0, the number is even.
# Since 0 is falsey, we have to invert it with not.
return not num % 2
while start
random_number = random.randint(1, 99)
if even_odd(random_number) = 0
print("{} is even".format(random_number))
else:
print("{} is even".format(random_number))
start -= 1
3 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsWhen a previous task is no longer work it is usually because new code contains a syntax error causing all testing and execution to fail.
In the case of your code, the following syntax errors exist:
-
if
statement does not end in colon (":") -
if
statement using assignment ("=") instead of comparison ("==") operator -
while
statement does not end in colon (":")
There are also two bugs in the code:
- The function
even_odd()
returns a Boolean. This can be used directly as theif
conditional statement. No need to compare to an integer - The second print statement also says "even" instead of "odd"
Post back if you need more help. Good luck!!
IAN WOOD
1,336 Points"When a previous task is no longer work it is usually because new code contains a syntax error causing all testing and execution to fail."
That's what I'm talking about - the Challenge environment often doesn't provide the information that you'd get from the console or the Workspace. While I'm booking along with the videos and Workspaces, I'm learning to read error messages, focusing on specific lines of code based on those, fixing them, and moving on - then I hit the Challenge space, and the feedback often drops to zero.
My question here wasn't really about what's wrong with the code for this particular challenge - that is, I don't want to be told what's wrong with it - not yet, anyway! - I want errors that I can use to figure that out myself. But I have to take the code elsewhere to do that, because "Oops! It looks like task One is no longer passing!" isn't a useful error.
So I'm really asking about the Treehouse environment, rather than Python - is there a reason that the Challenges are set up this way? (I mean yeah, I could skip them, but where's the fun in that? :) )
Chris Freeman
Treehouse Moderator 68,441 PointsThe difficulty is in designing the challenge checker to catch errors and report them out as best it can. My understanding is that the checker isn't running a simple Python REPL shell and access to the equivalent stacktrace is not directly available. So when a syntax error occurs, it throws up it's hands and says it's no longer passing. Not the best solution, but now you know what to look for in this case.. Perhaps, one of the limitations is the challenge system is used across all programming courses and not specific to Python.
When answering questions on the community forum, I also will copy them over to Workspaces or run locally to see the error. This is a great approach and more realistic of the real world problems.
IAN WOOD
1,336 PointsI think that'll be my approach, too...it's not a super critical thing, but I had the thought - "Wait, maybe this is supposed to get me used to asking forums like Stack Overflow for help...?" So I wanted to make sure it wasn't me just missing the point or something. And that makes sense, yeah - it's not Python-specific, and it doesn't replicate the shell.
So when I write broken code and get a less-than-helpful error, I'll just run it locally.
Thanks for the info - I've got a long way to go, here, and this helped me understand the lay of the land 'round these parts.