Randomly Chosen Function Operation on Inputs

  • Share this:

Code introduction


This function takes two arguments, randomly chooses one from three internally defined functions using random.choice, and returns the result of the function processing the input argument.


Technology Stack : random, built-in functions

Code Type : Function

Code Difficulty : Intermediate


                
                    
def aaaaaaa(arg1, arg2):
    import random
    def bbb(arg):
        return arg + 1
    def ccc(arg):
        return arg * 2
    def dddd(arg):
        return arg ** 3
    return random.choice([bbb(arg1), ccc(arg2), dddd(arg1 + arg2)])