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 (Retired) Pick a Number! Any Number! Imports

Random Number

The random number challenge #2 asks "Now make a function named random_num that takes an int argument. Return a randint between 1 and the passed-in number."

But my function wont pass, what is wrong with it?

random_num.py
import random

def random_num(int):
  random.randint(1, int)

1 Answer

Stephen Layton
Stephen Layton
8,643 Points

The randomly generated number is not currently being "returned". Adding return before random.randint should do the trick.

import random

def random_num(int):
  return random.randint(1, int)

For more info see http://learnpythonthehardway.org/book/ex21.html

Thank you, that did the trick.

That link is quite helpful as well!