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 trialMimon Copitman
1,242 Pointsi dont understand the challenge
dont understand the challenge
import random
def random_item(string)
index = random.randit(0,len(string))
index -= 1
return string[index]
3 Answers
james south
Front End Web Development Techdegree Graduate 33,271 Pointsyou are close. you are missing the colon after the function definition, and you misspelled the method used to get the random number.
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 PointsGood evening, there are a few errors in your code:
You need a colon at the dend of your def statement:
You have mis-spelt randint
The random number must be between 0 and the length of the string -1. So minus one there, not in the next line.
index = random.randint(0, len(string)-1)
Mimon Copitman
1,242 PointsThank you so much for your help