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 trialmamadou diene
Python Web Development Techdegree Student 1,971 PointsYou've seen how random.choice() works. It gets a random member from an iterable (like a list or a string). I want you t
i need some guidance in here. Please
# EXAMPLE
# random_item("Treehouse")
# The randomly selected number is 4.
# The return value would be "h"
import random
def random_item("table"):
random_number = random.randit(len("table") -1)
return random_number
3 Answers
Steven Parker
231,271 PointsHere's a few hints:
- variable names (and function parameter names) should not be enclosed in quotes
- the random method name is "randint" (with two "n"s)
- the "randint" method requires two arguments, a lower limit and an upper limit
- check indentation
mamadou diene
Python Web Development Techdegree Student 1,971 Pointsimport random
def random_item(table): random_number = random.randint(0,len(table) -1) return table<random_number>
here is more correction
Steven Parker
231,271 PointsPerhaps I should have said square brackets. []
mamadou diene
Python Web Development Techdegree Student 1,971 PointsIt worked!! thank you.
mamadou diene
Python Web Development Techdegree Student 1,971 Pointsmamadou diene
Python Web Development Techdegree Student 1,971 Pointsimport random
def random_item(table): random_number = random.randint(0,len("table") -1): return random_number
Here is the corrections i've made
Steven Parker
231,271 PointsSteven Parker
231,271 PointsBetter, but: