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 trialJesse Ferguson
1,419 Pointsrandom item
my code is not working and I need help again :|
# EXAMPLE
import random
def random_item(num):
random.randint(0 <= len(num) - 1)
return num
# random_item("Treehouse")
# The randomly selected number is 4.
# The return value would be "h"
1 Answer
Steven Parker
231,248 PointsYou're kind of close, here's some hints:
- the arguments given to a function should be separated with a comma
- you might need a variable to store what randint gives back
- you could then use that variable as an index to pick an item from num
- when you apply an index you enclose it in brackets ("[]")
I'll bet you can get it now without an explicit spoiler.