Python Python Basics (2015) Letter Game App Random Item

Please explain what I'm doing wrong?

I am not really sure what I am doing right or wrong I haven't been coding for 14 days oops. Please help.
import random 

def random_item[
    random.randint(0 < 8)
     random.randict - 1
        return random.randict
# random_item("Treehouse")
# The randomly selected number is 4.
# The return value would be "h"

2 Answers

Steven Parker
Steven Parker
187,453 Points

Here's a few hints:

  • when defining a function, the name must be followed by parentheses with the parameter(s) inside
  • you won't need to provide any data, the challenge will do that itself
  • the "randint" function takes two arguments separated by a comma
  • you'll need to use the length of the argument to get a random number in the right range
  • the "random" class has no "randict" property
  • the return value needs to be selected from the incoming argument

Hopefully this breaks down the steps for you

  1. random_item function needs an argument for iterable. syntax looks like: def func_name(arg):
  2. need to evaluate how many items are in this iterable to set the range for randomization. len(arg)
  3. determine random number. n=random.randint(1, len(arg))
  4. return the result. return arg[n-1]