+ 2
Python
How can I randomly select one of several functions and tell it to run?
2 odpowiedzi
+ 7
from random import choice
def f1():
print(2+3)
def f2():
print(4+5)
funcs = [f1, f2]
choice(funcs)()
+ 3
You can use the function random() to generate a random number and assign each number a function with if-else statements