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 trial

Python

Why does this script not work?

Why does this script not work?

def is_odd(number_input): test = number_input % 2 print (number_input) print(test) return test == 0

number_input = input("Enter a number: ")

3 Answers

Steven Parker
Steven Parker
243,228 Points

You didn't provide a link to the course page, but if I remember correctly the instructions only ask you to return the result. They don't ask you to "print" or "input" anything (and doing so will confuse the validator).

Steven Parker
Steven Parker
243,228 Points

For just testing, this code defines but doesn't call the function. Did you intend to do something like this after the input?

print(is_odd(int(number_input)))  # test the function

Also, doing " % 2" tests for even instead of odd. And there could be hidden formatting issues. When posting code to the forum, use Markdown formatting (as I did above) to preserve the appearance.

I added the extras for my own learning experience. I would not include them in my submission. Why does the script I wrote not work? I don't see what is wrong with it.

Thanks for the help. What is best way to create the markdown? I tried the three back ticks as in the video but that did not work.

Steven Parker
Steven Parker
243,228 Points

Were the 3 backticks on a line by themselves (or with only the language name following)?
That's important to make it work.

And if this resolves your issue, you can mark the question solved by choosing a "best answer".
Happy coding!

Are you saying do not use Python? I think you are saying use ``` by themselves on first line and last line. Is that right? What is the best way to test this?

Steven Parker
Steven Parker
243,228 Points

You can use the language name for syntax coloring. So the first line can be :point_right: ```python

An even better way to allow your issue to be precisely replicated is to make a snapshot of your workspace and post the link to it here.