Can you pick a random function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can you pick a random function?

If i import the random module, make functions and put them into a list, can i make the random module pick one and successfully execute the function?

5th Mar 2019, 1:07 AM
Sai
Sai - avatar
2 Answers
+ 2
import random my_list = [max, min, divmod, pow] x = random.randrange(len(my_list)) print(my_list[x](10, 2)) Possible outcomes: 10 # max 2 # min (5, 0) # divmod 100 # pow
5th Mar 2019, 1:25 AM
Diego
Diego - avatar
0
thank you!
5th Mar 2019, 1:39 AM
Sai
Sai - avatar