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

Python Python Basics (2015) Letter Game App Even or Odd Loop

Chad Dugas
PLUS
Chad Dugas
Courses Plus Student 13,304 Points

Wrong 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?

even.py
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
Jeff Hartl
seal-mask
.a{fill-rule:evenodd;}techdegree
Jeff Hartl
Python Web Development Techdegree Student 8,420 Points

Hi 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)

1 Answer

Steven Parker
Steven Parker
231,007 Points

:point_right: There's a few issues here:

  • the parentheses are not placed correctly in your print statements. See example below :arrow_heading_down:
  • 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".
parens.py
#       print("{} is even").format(rand_num)  <- parenthesis misplaced
        print("{} is even".format(rand_num))  #- fixed