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

Lucas Meader
Lucas Meader
1,657 Points

I think the testing AI is falsey ;p It's telling me that Task 1 is no longer passing. I can't see why.

Task 1 complete Task 2 complete Task 3 complete... won't let me pass because Task 1 is no longer passing?

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:
    rnum = randon.randint(1, 99)
    result = even_odd(rnum)
    if result is True:
        print("{} is even".append(rnum))
    else:
        print("{} is odd".append(rnum))

    start -= 1

2 Answers

Hi Lucas,

I think the main issue is using the .append() method on a string. You want to interpolate the value of the random number into the string; you've done the {} bit! So you need to call the .format() method to do that for you.

You can take the temporary variable out too, but that's not what's failing the challenge.

I came up with this:

while start:
    num = random.randint(1, 99)
    if even_odd(num):
        print("{} is even".format(num))
    else:
        print("{} is odd".format(num))
    start -= 1

I hope that helps,

Steve.

Lucas Meader
Lucas Meader
1,657 Points

Thank you Steve! You're quick and thorough.

No problem, and thank you! :smile: :+1:

Two issues:

1> in while loop, you meant to write, "random"

2> append method belongs to lists, you want to use format() here.

For more details, look into the code.

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:
    rnum = random.randint(1, 99)
    result = even_odd(rnum)
    if result is True:
        print("{} is even".format(rnum))
    else:
        print("{} is odd".format(rnum))

    start -= 1

Also, when you get an error, #previous_task not passing anymore, its just that there are syntax error in the new code.

Good spot with the random typo. :smile:

Lucas Meader
Lucas Meader
1,657 Points

ha ha, thank you, I keep spelling that wrong for some reason.

That's got me through.

All the best.

:+1: