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

Darren Taylor
Darren Taylor
1,052 Points

Even.py Challenge, Task 1 of 3... I'm stuck on this challenge, please help.

The question reads:

For this challenge, we're going to need to use the random library. Add an import to the top of your file to bring it in.

even.py
def even_odd(num):
    if num % 2 == 0:
        return True
    else:
        return False

2 Answers

Remember, the random module must be imported before each time you use it. you wouldn't be able to use random.randint() or any other random function for that matter unless you import it first. Think of import as defining the module. Just like you won't be able to call on a variable (my_var) unless you assign it (my_var = 123), you won't be able to call on a module unless you import it.

The way to import a module in python is using the import keyword:

import random

random.randint(0,4)
Kaci Jenkins
Kaci Jenkins
860 Points

I am stuck on this challenge as well. Mine does NOT tell me to import the random library?