Nikhil Alexander1,444 Points
this code does seem to pass the challenge
im not sure whether to subtract one from the length of the iterable or from the random number.. if im making some other mistake please help me correct it
import random random_num = random.randint(0, 7) def random_item(Avengers): return(Avengers[random_num])
Steven Parker177,888 Points
The random number should be selected inside the function, and the range should be based on the size of the argument instead of any fixed value.
Dan Garrison22,438 Points
The code challenge is asking you to give a random number between 0 and the length of the iterable provided as the argument minus 1. To do this you need to use the built in python function, len() to determine the length of the incoming argument. Remember, functions are reusable code snippits. They are useful because you don't always know what the input will be. In this case they could give you an iterable (string, list, etc) that is 10 characters in length and another time you could get an iterable that 15 characters in length. Your function should be capable of handling both.
You should not be declaring any variables outside your function. In fact, you can even complete the challenge without declaring a variable.