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

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,271 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 !