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 trialChad Dugas
Courses Plus Student 13,304 PointsWrong number of prints.
Not sure where I'm going wrong here. I get the error message "Wrong number of prints." Whenever I change the code to try to correct this, it tells me Task 1 is no longer complete. Can anyone see the issue?
import random
start = 5
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
while start == True:
rand_num = random.randint(1,99)
if even_odd(rand_num) == True:
print("{} is even").format(rand_num)
else:
print("{} is odd").format(rand_num)
start -= 1
1 Answer
Steven Parker
231,269 PointsThere's a few issues here:
- the parentheses are not placed correctly in your print statements. See example below
- comparing a number to a boolean will invoke type coercion, which will give you the wrong result.
- you don't need to compare anything against "True". Just naming it is enough to test its "truthiness".
# print("{} is even").format(rand_num) <- parenthesis misplaced
print("{} is even".format(rand_num)) #- fixed
Jeff Hartl
Python Web Development Techdegree Student 8,420 PointsJeff Hartl
Python Web Development Techdegree Student 8,420 PointsHi Chad, In both of your print statements, there's a parenthesis in the wrong place. Do you see where?
(I've made the same syntax mistake myself)