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

or porat
or porat
684 Points

Didn't understand the question

Hey! First thing, what is "iterable"? second thing, i didnt understand how to use 'random.randit()' what what to do after that. thanx!

item.py
import random

def random_item("apple"):
    random.randit()




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

1 Answer

Steven Parker
Steven Parker
231,275 Points

:point_right: "Iterable" is basically "capable of being stepped through, one item at a time".

Most (but not all) collections of items are iterable. A common example would be lists.

For your second question, the actual name of the function is randInt (with an "n"), and it takes two arguments that indicate minimum and maximum values. It will return a random integer value chosen between the two arguments provided.

For example, this code will print a random number between 0 and 9:

print(random.randint(0,9))
or porat
or porat
684 Points

thanx alex! i wrote the cod like this now:

import random

def random_item("apple"): print(random.randit(0,3)) return "apple"

but still i need to fix something. what's wrong? i think i did'nt understand what to return

Did you just call Steven Parker Alex?! Lol

Anyway, I noticed you actually can't and shouldn't use double/single quotes for parameter string names.

For more detail look below in my answer.