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

Randall Brewster
Randall Brewster
5,041 Points

Now make a function named random_num that takes an int argument. Return a randint between 1 and the passed-in number.?

cant seem to get this one to work what am i doing wrong"

random_num.py
import random
random_num = random.randint (1,10)

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

The way you make use of random.randint is correct, but unfortunately, this problem is asking you to

make a function named random_num that takes an int argument.

Your code only assign the value of random.randint to a variable, you didn't define a function.

import random

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