I’m trying to run a script that takes five functions in a list, and picks one at random using the random module.
myList = [quote1(), quote2(), quote3(), quote4(), quote5()]
def random_output(): random.choice(myList)
print(random_output)
However, upon running, it just prints all of the quotes at the same time, followed by <function random_output at 0x0000019F66EF4430>.
>Solution :
You should put your functions in myList, not the result of their call. Then call the function after selecting it with random.choice:
myList = [quote1, quote2, quote3, quote4, quote5]
def random_output():
# select a random function
# call it, and return its output
return random.choice(myList)()
print(random_output())