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 trialKelly Ferrell
2,561 Pointsfunction named random_num exercise says that task 1 is no longer passing. what am I doing wrong?
I have tried several time to get this code to run but on the second task it says that task 1 is no longer passing. Help!
import random
def rand_num():
rand_num = random.ranint(1,10)
1 Answer
Matthew Rigdon
8,223 PointsWhen you define rand_num, make sure you allow it to take in another integer (number). To do that:
import random
def rand_int(int):
Now, the user can input any number. Next, make sure to watch your spacing. The line:
rand_num = random.randint(1, int)
Should be indented further than your def rand_int(int) line. Press tab to do that. Right now, your code does not return an actual answer. In order to have a function return a value, you must use the return command, which will come after your assigment of the rand_num variable. Try this:
return rand_num
Put together all of my suggestion and you should have working code.