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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![marinmirosevic](https://secure.gravatar.com/avatar/7a68298d92e763a4eb985003127fb9f4?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
marinmirosevic
3,279 Pointshi...need help with this code. thanks
hi...need help with this code. thanks
import random
secret_num=random.radnint(1,10)
while True:
even_odd=int(input("Put a number"))
if even_odd==secret_num:
print("YouGoIt MyNumberwas{}".format(secret_num))
break
else:
even_odd_1=even_odd/2
if int(even_odd_1)=even_odd_1:
print("Number is even")
else:
print("Number is not even")
6 Answers
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 Points
It looks like you may have copied from a different challenge (or two!).
You might want to read the challenge instructions again carefully. Some of what it asks for is very different from what you wrote:
- the challenge asks you to write a function
- your function will require and test a passed argument
- it will not need to input anything
- it will not need any random value
- the function will return the result
- the results will only be True and False
- it will not need to print anything
Try again, and be careful to do only what the instructions ask for.
![vikas pal](https://secure.gravatar.com/avatar/7827f154b2716ccfe9a028f89b9eb987?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
vikas pal
11,563 Pointsyour randint spelling is wrong in line 2
random.randint(1,10)
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 Points Knowing the correct spelling of randint might be useful in the future, but it will not help this challenge.
![marinmirosevic](https://secure.gravatar.com/avatar/7a68298d92e763a4eb985003127fb9f4?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
marinmirosevic
3,279 Pointsthanks Steven
does this looks better?
def even_odd(number): number=6 number_1=6/2 if int(number_1)==number_1: True else: False
![Robin *](https://secure.gravatar.com/avatar/bfbbb2bca23a2d5df1fc0f4c74a7f1ab?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Robin *
5,670 PointsThere is no need to define the number inside the function. The number is passed to the function when it is called for example: even_odd(3) where 3 is the 'num'
You should use a modulo operation in order to figure out if the number has a rest value or not. In python % is the operator for a modulo operation. for example: 5 % 2 = 1 It is 1 because 5 divided by 2 leaves a quotient of 2 and a remainder of 1.
If you are still reading this then you might have realized that if you take an odd number and MOD by 2 you will get a value that is "Truthy" and if you take an even number and MOD by 2 you will get a value that is "Falsy". So our even_odd function we have to take that in to consideration.
We can achieve this by using the not operator.
def even_odd(num):
return not num % 2
We could also do it like this
def even_odd(num):
if num % 2 == 0:
return True
else:
return False
![marinmirosevic](https://secure.gravatar.com/avatar/7a68298d92e763a4eb985003127fb9f4?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
marinmirosevic
3,279 Pointsthanks
![Windy Elliott](https://secure.gravatar.com/avatar/bda5170281a329716e2fce7fcab27c6d?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Windy Elliott
776 PointsThank you all!!