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
Alvand Hajizadeh
2,069 PointsCan't seem to get my basic Python function to work.
This is my code:
def is_odd(value):
if value % 2 == 0:
print("False")
else:
print("True")
return value
This is the question:
Let's create a function that determines if a specific value is odd. Let's name the function is_odd and have it declare a single parameter. It should return True if the value is not divisible by 2.
Please let me know if can help! Thank you!
1 Answer
Alex Koumparos
Python Development Techdegree Student 36,888 PointsHi Alvand,
Without properly formatting your code using Markdown (see the Markdown Cheatsheet below the text entry box) it's impossible to determine what your actual code looks like (for example, there is no way to tell whether your return value statement is inside your else branch, or outside it, or even outside your function). I'm going to assume that it looks like this:
def is_odd(value):
if value % 2 == 0:
print("False")
else:
print("True")
return value
In this case, you print True or False to the console (which is not asked for in the question) and return the value of value (instead of True or False).
For example, if the input value to your function was 7, your function should return True:
It should return True if the value is not divisible by 2.
But your function wouldn't return True, it would return 7.
Cheers
Alex