Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (Retired) Pick a Number! Any Number! Imports

"Code Challenge: Imports" -- Game -- contradictions from "Check Work"!

This exercise provides contradictions when I "Check Work".

The exercise seems to demand that I create a function 'random_num()' -- which will not accept an argument as demanded -- and also the exercise specifies that the function 'random_num' should accept an argument. (of type int).

You can't have it both ways. Either you provide an argument in the definition of the function, or you don't. Am I missing something?

import random

def random_num():
  return randint(1,num)

1 Answer

When defining the function you need to allow a placeholder for the input.

Like this;

def add_two(input):
    some_value = input + 2
    return some_value

See how 'input' shows up in two places in this example function.

As you have it written in your example, you aren't passing in the 'num' that you are trying to use in your return statement. You need to pass it in, so that it can be used.