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

even.py

Not sure why it keeps telling me I have the wrong number of prints \n other times it tells me on the 3rd task that I'm no longer in agreement with 1st task

even.py
import random
start = 5
def even_odd(num):
  start = 5
  while start is truthy:
    if num % 2 is 0:
      print("{} is even".format(num))
      continue
    else:
      print("{} is odd".format(num))
      continue
    start -= 1

1 Answer

Zach Swift
Zach Swift
17,984 Points

When the challenge starts out, he gives you the even_odd function. He wants you to use that to check the random number you generate in the loop. So everything you write should be outside of that function.

Secondly, in your while loop, you have while start is truthy but you just need while start. That checks truthiness.

thirdly, when it gets to the continue statements it skips the decrementing of the start variable. You don't need the continue statements. If/else are exclusive so if your program goes down one path, it will not go down the other.

Lastly, in the code you posted, you're not generating a random number like he asks. Here is an example of one way to do 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:
  random_num = random.randint(1, 99)
  if even_odd(random_num):
    print("{} is even".format(random_num))
  else:
    print("{} is odd".format(random_num))
  start -= 1

Thank you for your very thorough feedback! I think I'm getting a bit too tired for quality mental effort. I'll come back to it tomorrow.

Thanks again, Zach!