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

I dont see whats wrong with my code (Now make a function named random_num that takes an int argument...)

I keep getting an error that says "can't seem to call random_num() with an argument."

random_num.py
import random
list = [1,2,3,4,5]
def random_num(list):
    return random.randint(1, len(list)-1)

2 Answers

Chris Adamson
Chris Adamson
132,143 Points

The challenge is looking for a number to be passed in, not a list:

import random

def random_num(num):
    return random.randint(1, num)
Dan Johnson
Dan Johnson
40,532 Points

The argument being passed in is an int representing the upper range of the random number. Getting rid of the call to len should help.

You also won't need to define any input to be passed in. The challenge will deal with that.

Great! it worked.Thanks guys.