+ 2

Python

How can I randomly select one of several functions and tell it to run?

27th Sep 2023, 6:11 PM
Fateme Biglari
Fateme Biglari - avatar
2 odpowiedzi
+ 7
from random import choice def f1(): print(2+3) def f2(): print(4+5) funcs = [f1, f2] choice(funcs)()
27th Sep 2023, 7:34 PM
JaScript
JaScript - avatar
+ 3
You can use the function random() to generate a random number and assign each number a function with if-else statements
27th Sep 2023, 7:28 PM
Niro
Niro - avatar