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

fahad lashari
fahad lashari
7,693 Points

I have no idea what I am doing wrong...code challenge[solved]

My code works just fine when I test in workspaces however it seems to not work here. Confusing. Can someone please let me know what I am doing wrong

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

def random_item(tree_house):

    print(tree_house[random.randint(0, (len(tree_house)-1))])

random_item("Treehouse")
fahad lashari
fahad lashari
7,693 Points

Dont worry guys i figured out my stupid problem. I forgot to change 'print' to 'return'. I was testing the code out in workspaces

Maybe mark the question as answered then. :) Good job doing your own debugging!

1 Answer

fahad lashari
fahad lashari
7,693 Points

Oops :p how do I do that?

There should be a button beneath an answer that you can select that says something along the lines of "best answer".

It just helps for people who are browsing over looking for questions to help on if they can see that this one is solved.