I’m a total begginer in programming 🙂
I’m trying to solve a coding challange which instructs me to
pick a random name out of a list but i’m not allowed to use the .choice function
instead I somehow need to pick an item out using the len() function
in my code.
# Split string method
names_string = input("Give me everybody's names, separated by a comma. ")
names = names_string.split(", ")
# 🚨 Don't change the code above 👆
#Write your code below this line 👇
import random
>Solution :
Try this:
result = names[random.randrange(len(names))]
This is also a possible solution:
result = names[random.randint(0, len(names) - 1)]