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 trialAngela Anders
1,844 Points"Create a function" practice exercise This is what I was asked to do, but I can't figure out if I'm on the right track.
Challenge 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.
Here is a link to my code in workspaces:
open up the 'create_a_function.py' file
1 Answer
Chris Freeman
Treehouse Moderator 68,454 PointsYou have the general idea. There are some syntax issues to clean up:
def is_odd(number,2): # do not need to pass in constant, remove ", 2"
if 0 = (number % 2) # if needs trailing colon (:), compare uses double equal (==)
print("False") # should return False, not print it
elif 1 <= (number % 2): # a condition uses 'elif', without condition use 'else'
print("True") # should return True, not print it
Running the fixed code in the REPL:
$ python
Python 3.6.3 (default, Oct 3 2017, 21:45:48)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def is_odd(number):
... # your fixed code here
... pass
...
>>> is_odd(4)
False
>>> is_odd(5)
True
Post back if you need more help. Good luck!!
Angela Anders
1,844 PointsThanks Chris! That was very helpful!
syed bukhari
4,028 Pointssyed bukhari
4,028 PointsI still cannot get this, can you help?
Thank you