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 trialPratham Patel
4,976 PointsCan i have the answer to this
i dont want an explanation just an answer
# EXAMPLE
# random_item("Treehouse")
# The randomly selected number is 4.
# The return value would be "h"
Mike Wagner
23,559 PointsSteven Parker - I wish I could upvote comments just because of how true that is. I usually try to avoid the explicit answers unless a person is really close, but an explanation is almost always necessary. If you don't help them understand why it wasn't working or how you made it work, you're just dooming them to have more questions in similar scenarios.
Steven Parker
231,275 PointsThis seems to be an extreme case, with 4 requests for explicit answers in just the last 2 hours. I think you answered 3 of them yourself.
The real shame of spoilers is that even if one person wanted them, when others only wanting hints search for help they will encounter them also.
Mike Wagner
23,559 PointsSteven Parker - Yeah, I agree with the "extreme case" thing, and yes I did answer this one explicitly, even though no attempt had been made, but the other 2 they were pretty close on. This one is where I actually made a point in saying something, as no real attempt had been shown, but I answered it because of the simplicity of the problem and because I'm in a generous mood today, haha. I'd be working my own material, but I'm having ISP issues and can't play the videos at the moment, but I wanted to do something to exercise my mind a bit.
Pratham Patel
4,976 PointsYou both are right. I am sorry for being lazy. Next time i will attempt it many times before getting help
Steven Parker
231,275 PointsThat's good to hear ... but as much as that, I think what threw us was the "no explanation just an answer" request. Do you really learn better that way?
Pratham Patel
4,976 Pointsi guess i was just really mad that i couldn't do the challenge which is why i just wanted an answer
Steven Parker
231,275 PointsIt's really difficult to solve problems when you're frustrated. Try using that time to take a break, do something entirely different for a while. And when you come back to it later sometimes things that seemed nearly impossible before might not seem so difficult any more.
1 Answer
Mike Wagner
23,559 PointsYou probably shouldn't be in a place to learn something if you're just looking for handout answers. That said the solution is pretty simple.
import random #import the necessary library
def random_item(iterable): # pass in the iterable
return iterable[random.randint(0, len(iterable)-1)] # return the member of the iterable at the random index
Steven Parker
231,275 PointsSteven Parker
231,275 PointsThere seem to be a lot of folks around recently that love to leave explicit spoiler answers, one is likely to come by shortly.
But really, you don't want any explanation? Wouldn't that help you you to learn? Or are you here for something else?