Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Letter Game App Random Item

return value - What am I missing? Its working on my IDE.

What am I missing here? I have tried many times, including in my IDE and it works as it's being requested. Why is the system not accepting it? It says that it didnt get a correct response/return from random_item.

item.py
# EXAMPLE
# random_item("Treehouse")
# The randomly selected number is 4.
# The return value would be "h"

import random
def random_item(word):

    random_num = random.randint(0, (len(word)-1))
    return print('The return value would be "{}"'.format(word[random_num]))

        #print("The randomly selected number is {}.\n".format(random_num))
        #print('The return value would be "{}"'.format(word[random_num]))

random_item("Treehouse")

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,258 Points

you are doing some things the challenge doesn't ask for. it says return but you are printing, and also the iterable is not necessarily a word. it doesn't want a long string, just the element at the random index, per the examples.

Ah! - Thanks James !