Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Practice Creating and Using Functions in Python Practice Functions That's Odd

Blue DiamondXD
Blue DiamondXD
5,369 Points

what shoul i put in between the () it doesent say what to add

create_a_function.py
def is_odd(num):
    if 

2 Answers

Josh Keenan
Josh Keenan
19,426 Points

What you have between the () currently, num, is perfectly fine.

Now you have to figure out if a number is odd, to check if a number is divisible by 2 you need to use the % operator. It checks if there is a remainder, so if there is a remainder we know it is an odd number.

Hope this helps, feel free to ask for help if needed, good luck!

Blue DiamondXD
Blue DiamondXD
5,369 Points

but how do i use the % im kind of connufuss

Josh Keenan
Josh Keenan
19,426 Points

If we wanted to know if a number was divisible by 3, it would look like this:

if num % 3 == 0:

This says, if the number is divisible by 3, then we can do whatever.

You want to check if it is NOT divisible by 2

Blue DiamondXD
Blue DiamondXD
5,369 Points

ohhh i get it now thanks i migth have a idea now

Josh Keenan
Josh Keenan
19,426 Points

You got this, I believe in you!

Blue DiamondXD
Blue DiamondXD
5,369 Points

by the way should i make a variable for num???

Josh Keenan
Josh Keenan
19,426 Points

num is already like a variable itself, you don't ever need to make a variable for a parameter, you can just use the parameter in the same way.

Blue DiamondXD
Blue DiamondXD
5,369 Points

def id_odd(num): if num % 4 == 2: answer = True elif num % 5 == 1: answer = False return answer

result = int(input("fagagaaga"))

i try is but it doesent work

Josh Keenan
Josh Keenan
19,426 Points

You were close:

def is_odd(num):
    if num % 2 != 0:
        return True
Blue DiamondXD
Blue DiamondXD
5,369 Points

thank you for you time you a great person thank you for you time

Josh Keenan
Josh Keenan
19,426 Points

!= is the not equal to operator