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 trial

Python Python Basics (2015) Letter Game App Random Item

Mimon Copitman
Mimon Copitman
1,242 Points

i dont understand the challenge

dont understand the challenge

item.py
import random

def random_item(string)
    index = random.randit(0,len(string))
    index -= 1
    return string[index]

3 Answers

Christopher Shaw
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 Points

Good evening, there are a few errors in your code:

  1. You need a colon at the dend of your def statement:

  2. You have mis-spelt randint

  3. 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
Mimon Copitman
1,242 Points

Thank you so much for your help