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

Justin Kinney
Justin Kinney
445 Points

what dose it mean by return randint between 1 and a number passed in?

im sort of confused when it ways a number passed through!

random_num.py
import random

def random_num():

1 Answer

Hi Justin Kinney,

when you define a function with an argument list, the caller of this function then can pass in the needed arguments between the parentheses. Let's say somebody uses your function. Therefore you should declare the function with an argument. You can handle that argument(s) then within the logic of your function.

Example:

import random

def random_num(number):       
    return random.randint(1, number)  #This takes the given argument and uses it as a parameter

the return just says, that you return something back to the function when it get's called. You could for example pass the value to a variable if you wanted.

variable = random_num(5) #calls the function and assigns the return value to the variable

which would call your function with 5, so that your function returns random.randint(1, 5) and assigns it to the variable.

Got it? Maybe I explained it a little too complicated. If you still need help just asked :-)