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 trialTyler Weston
1,168 PointsWrong number of prints?
When I run this code, it says there is the wrong number of prints and I don't know how to fix this.
import 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 == True:
num = random.randint(1, 99)
if even_odd(num) == 0:
print("{} is even".format(num))
else:
print("{} is odd".format(num))
start -= 1
1 Answer
Garrett Hughes
Python Development Techdegree Student 32,971 Points1st: love the GOT profile pic.
2nd: Line 6, "return not num % 2", isn't returning ints or floats, it's returning booleans (True or False)
Try running:
def even_odd(num):
print(not num % 2)
even_odd(22)
even_odd(33)
even_odd(44)
even_odd(55)
even_odd(66)
in workspaces or repl.it to see what I'm talking about. Reexamine your code and see if you can figure it out after that.
Tyler Weston
1,168 PointsTyler Weston
1,168 PointsThanks. I make silly mistakes like that sometimes. I'm glad you liked my profile picture; your Deadpool one is great too.