Bummer! You must be logged in to access this page.

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

Practice Creating and Using Functions in Python

Can't ask the forum for help on task 1 of 1

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.

def is_odd(number): if number % 2 != 0: print("true")

7 Answers

Hi Richard, the only tricky part in the challenge is the one with the modulo operator. You can use

if parameter % 2 != 0:
    return True

befor this you naturally have to define your is_odd function with the parameter as the argument, or whatever you want to name it ... I hope this helps you solve the challenge ...

num = int (input ("Enter number: ")) def is_odd (num): if num % 2 != 0: return True else: return False I don't know why it is giving me error

This should work: def is_odd(value): if value % 2 != 0: return True

can you post the exact challenge again ... I answered but now I wanted to check again and give you more of a hint ... but can't find the challenge, if you would post it ... than I could have another look ... I recall, that only the modulo operator thing was tricky, but I'd look again ... regards, Jan.

def is_odd(num): if num % 2 != 0: return True else: return False

that doesn't help but thank you

Hi Richard,

When determining whether a number is odd or even, we typically use the modulo operator, which returns the remainder of the 1st number divided by the 2nd.

E.g. 5 % 2 = 1

An even number can be expressed as 2n, while an odd number can be expressed as 2n + 1.

What are the differences when you use modulo on odd or even number? i.e. 5%2 vs 4%2?

To help you internalise, I will leave it to you to find out for yourself. Let me know if you still don't understand how to do it, and I will explain further.