python - Syntax to call random function from a list -


Text after "

From this formula:

I found out that it is possible to put some actions in a list , And by calling random.choice () , call one of them to generate a random event.

I am interested in doing this because I am writing a very small text based game right now part of the tutorial of the beginning

But when I write what I think will give me the desired result ( That is, one of the tasks is being said and its string is printing.

  import random id func_test_1 (): print "this is func_test_1." Def func_test_2 (): print "this func_test_2 "DEF func_test_3 (): print". This is func_test_3 that "my_list = [func _test_1 (), func_test_2 (), func_test_3 ()] random.choice (my_list)   

I get this result:

  C: \ Windows \ System32 \ cmd.exe / c Dragon \ random_func.py This is func_test_1.It is func_test_2.It is func_test_3. Hit any key this window ...  to stop  

all three functions Which is calling and printing.

Can someone help me do this with the right syntax? Thank you.

You call functions with brackets. Do you want to tell them later in the list and say:

  my_list = [func_test_1, func_test_2, func_test_3] random.choice (my_list) ()    

Comments