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 trialForrest Iarwain
461 Points"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
Matthew Carr
11,220 PointsWhen 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.