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

Denis Ts
Denis Ts
2,751 Points

Hello guys. What is wrong here? Probably i didit get the Task correctly ?

import random

start = 5 def even_odd(): rund_num = random.randint(1, 99) num = rund_num % 2 return not num % 2

while start > 0: num = even_odd() if num == 0: print("{} is even".format(num)) else: print("{} is odd".format(num)) start -= 1

even.py
import random

start = 5
def even_odd():
    rund_num = random.randint(1, 99)
    num = rund_num % 2
    return not num % 2

while start > 0:
    num = even_odd()
    if num == 0:
        print("{} is even".format(num))
    else:
        print("{} is odd".format(num))
    start -= 1

1 Answer

Steven Parker
Steven Parker
231,007 Points

:point_right: You have a few issues here:

  • you should create a random number in your loop
  • you should not modify the provided even_odd function
  • you can use the provided function to test your random number
  • when testing a boolean, you don't need to compare it to anything (it's already "true" or "false)
  • you can determine if "start is falsey" by testing it as you would a boolean