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!
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
random_member function I think my answer is right!!
import random def random_member(arg): v = len(arg) v = v-1 return random.choice(v)
Now, make random_member pick a random number between 0 and the length of the list, minus 1. So if the length was 5, get a number between 0 and 4.
Return the list item with that index
[MOD: added ```python markdown formatting -cf]
Chris FreemanTreehouse Moderator 68,404 Points
random.choice operates on a sequence (an object that has length). Using you are calling it with an
Your code will pass if modified:
import random def random_member(arg): # v = len(arg) # v = v-1 return random.choice(arg)
This code works, but the intent of the challenge is to use
random.randint() to create a random number and use it as an index into
import random def random_member(arg): # return len(arg) # Task 2 random_index = random.randint(0, len(arg)) return arg[random_index]
This one is off topic but python seems to be difficult to read the functions using help()
dir(random) shows a list of built in functions so I choose Random help(random.Random)
doesnt show much usefull information on how to use it so maybe I just chose one too advanced? my coments in ## just trying to figure out how would you use it....
Random number generator base class used by bound module functions.
| Used to instantiate instances of Random to get generators that don't
| share state.
| Class Random can also be subclassed if you want to use a different basic
| generator of your own devising: in that case, override the following
| methods: random(), seed(), getstate(), and setstate().
| Optionally, implement a getrandbits() method so that randrange()
| can cover arbitrarily large ranges.
| Method resolution order:
| _random.Random ## right here is syntax style on degraded obsolete modules???
| Methods defined here:
| # Issue 17489: Since __reduce_ was defined to fix #759889 this is no
| # longer called; we leave it here because it has been here since random was
| # rewritten back in 2001 and why risk breaking something.
| ## ah down here is obsolete.
| init(self, x=None)
| Initialize an instance.