Welcome to the Treehouse Community
Looking to learn something new?
"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
Chris FreemanTreehouse Moderator 67,987 Points
You 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!!