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 trialfahad lashari
7,693 PointsI don't really have an idea what they are asking me to do. I am novice so here is my crappy code...
Could some one please help me out with this task. And If you have the time, please can you explain what they are asking me to do.
kind regards,
import random
start = 5
def even_odd(num):
If % 2 is 0:
return num is % 2
else:
return not num % 2
while start not 0:
number = random.randint(1, 99)
if even_odd(number) == num is % 2:
print('{} is even'.format(number))
else:
print('{} is odd'.format(number))
start-=1
2 Answers
john larson
16,594 Pointsimport random
def even_odd(num):
# If % 2 is 0, the number is even.
# Since 0 is falsey, we have to invert it with not.
return not num % 2
start = 5
while start:
number = random.randint(1, 99)
if even_odd(number):
print('{} is even'.format(number))
start -= 1
else:
print('{} is odd'.format(number))
start-=1
fahad lashari
7,693 PointsHi john,
I already figured this one out and forgot to take off the question. Thanks for you answer!
Your help is much appreciated
Kind regards,
john larson
16,594 PointsWell done then :D
john larson
16,594 Pointsjohn larson
16,594 PointsIt's a confusing one. Leave the even_odd() function as it is in the challenge. You don't need to do anything to it. The decrease increment will need to be in both the if and else. I got an INVALID SYNTAX on: