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

Alex Jones
Alex Jones
851 Points

Code works in workspace but when I run it in the task area it says "Oops! It looks like Task 1 is no longer passing"

Challenge Task 2 of 2

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

random_num.py
import random

userInput = input()

def random_num(intArg1):
  print(random.randint(1, int(intArg1)))
random_num(userInput)

1 Answer

Hi Adam

you dont need to print the random number generated nor do you need to call the function.

import random

def random_num(myInt):
  return random.randint(1,int(myInt))
Blair Owens
Blair Owens
8,235 Points

I'm curious how I should have got this answer. Don't recall learning that in the previous lessons.

For some reason, this is not working for me. Is it a glitch in the system?

import random
def random_num(inum):
return random.randint(1, inum)

The return actually is at the same level as the def statement. This does work in Workspaces. Am I misunderstanding what the question is?