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 Python Basics (2015) Number Game App Even or Odd

jamie Macdiarmid
jamie Macdiarmid
2,048 Points

Need help

Can someone show me how its done please?

I think it wouldn't be a bad idea if say after 20 mins of not knowing what to do a solution would be made available with perhaps some cliff notes on it.

What does anyone else think?

even.py
def even_odd(num):
  if num == (num/2)

2 Answers

Tobias Helmrich
Tobias Helmrich
31,601 Points

Hey Jamie,

to solve this challenge you have to use the modulo operator (%) which gives you the remainder of a division. If there is no remainder when you divide a number by two it's even and then you have to return True. Otherwise you have to return False as it's not even/odd:

Like this:

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

And I think that's a good suggestion. However I imagine it a bit hard to implement as it's a bit hard to guess where exactly the student may have problems so I think a forum is a better way as it provides more individual feedback.

I hope that helps! :)

jamie Macdiarmid
jamie Macdiarmid
2,048 Points

Thankyou so much Tobias. It was pretty simple after all. Doh!!

Tobias Helmrich
Tobias Helmrich
31,601 Points

No problem, I'm glad I could help! :)

Melanie Villela
Melanie Villela
3,048 Points

Hi Tobias I have a question. Could you put any value to replace (num) like could you type (x) as long you write the same (x) with the if statement?

Tobias Helmrich
Tobias Helmrich
31,601 Points

Hey there Melanie,

yes, you can name the parameter however you want and x would work just as fine as num! :)