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 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,602 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,602 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,602 Points

Hey there Melanie,

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