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 really dont understand what this task is asking me to do....code challenge[solved]
I really dont have an idea of what this task is asking me to do. I had a go at it but I keep getting 'Oops! it looks like Task 1 is no longer passing'. I then click on 'Go to task One', it passes without any additional changes and then I come back, change things and it does the same again.
Could someone please help me out. I apologise in advance if my novice code brings pain to your eyes
kind regards
import random
start = 5
def even_odd(num):
If % 2 is 0:
return num % 2
elif not %2 is 0:
return not num % 2
while not start == 0:
number = random.randint(1, 99)
if even_odd(number) == num % 2:
print('{} is even'.format(number))
elif even_odd(number) == not num % 2:
print('{} is odd'.format(number))
start-=1
1 Answer
fahad lashari
7,693 PointsDont worry guys, I finally figured it out. It seems though to pass some of these code challenges you have to figure out all the errors by first testing your code in the treehouse workspace. Here is my solution:
import random
start = 5
def even_odd(num):
if num % 2 == 0:
return True
elif not num % 2 == 0:
return False
while not start == 0:
start-=1
number = random.randint(1, 99)
if even_odd(number):
print('{} is even'.format(number))
elif not even_odd(number):
print('{} is odd'.format(number))
Do let me know if you see any improvements that could be made
kind regards