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
Richard Thomas
3,029 PointsPractice Creating and Using Functions in Python
Can't ask the forum for help on 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.
7 Answers
Jan Oberreiter
78,021 PointsHi Richard, the only tricky part in the challenge is the one with the modulo operator. You can use
if parameter % 2 != 0:
return True
befor this you naturally have to define your is_odd function with the parameter as the argument, or whatever you want to name it ... I hope this helps you solve the challenge ...
Selemawit Gebremedhin
1,331 Pointsnum = int (input ("Enter number: ")) def is_odd (num): if num % 2 != 0: return True else: return False I don't know why it is giving me error
Joshua Ouma
20,865 PointsThis should work: def is_odd(value): if value % 2 != 0: return True
Jan Oberreiter
78,021 Pointscan you post the exact challenge again ... I answered but now I wanted to check again and give you more of a hint ... but can't find the challenge, if you would post it ... than I could have another look ... I recall, that only the modulo operator thing was tricky, but I'd look again ... regards, Jan.
KRIS NIKOLAISEN
54,974 PointsUse the modulo operator %
Prince Samson Hotera
2,566 Pointsdef is_odd(num): if num % 2 != 0: return True else: return False
Richard Thomas
3,029 Pointsthat doesn't help but thank you
Jinjia Lin
11,942 PointsHi Richard,
When determining whether a number is odd or even, we typically use the modulo operator, which returns the remainder of the 1st number divided by the 2nd.
E.g. 5 % 2 = 1
An even number can be expressed as 2n, while an odd number can be expressed as 2n + 1.
What are the differences when you use modulo on odd or even number? i.e. 5%2 vs 4%2?
To help you internalise, I will leave it to you to find out for yourself. Let me know if you still don't understand how to do it, and I will explain further.
Duc Vo
Front End Web Development Techdegree Student 16,132 PointsDuc Vo
Front End Web Development Techdegree Student 16,132 Pointsdef is_odd(number): if number % 2 != 0: print("true")