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 trialannikaheflin
577 PointsPlease explain what I'm doing wrong?
I am not really sure what I am doing right or wrong I haven't been coding for 14 days oops. Please help.
import random
def random_item[
'life'
'love'
'live'
'learn'
'eat'
'pray'
'enjoy'
'happy']:
random.randint(0 < 8)
random.randict - 1
return random.randict
# EXAMPLE
# random_item("Treehouse")
# The randomly selected number is 4.
# The return value would be "h"
2 Answers
Steven Parker
231,275 PointsHere's a few hints:
- when defining a function, the name must be followed by parentheses with the parameter(s) inside
- you won't need to provide any data, the challenge will do that itself
- the "randint" function takes two arguments separated by a comma
- you'll need to use the length of the argument to get a random number in the right range
- the "random" class has no "randict" property
- the return value needs to be selected from the incoming argument
cb123
Courses Plus Student 9,858 PointsHopefully this breaks down the steps for you
- random_item function needs an argument for iterable. syntax looks like: def func_name(arg):
- need to evaluate how many items are in this iterable to set the range for randomization. len(arg)
- determine random number. n=random.randint(1, len(arg))
- return the result. return arg[n-1]