我正在尝试列出可以从中随机提取其中一个功能的功能列表。我尝试了几种方法,既试图让它主动选择列表中的第二个函数,也试图让它随机化。两者都失败了。如果列表中包含文本而不是函数,则该列表工作正常。 q = [opt1(), opt2(), opt3()]尽管我没有调用它们,但也会激活该功能。如何使它从列表中随机提取其中一个功能?import randomdef opt1(): print("hej1")def opt2(): print("hej2")def opt3(): print("hej3")q = [opt1(), opt2(), opt3()]health = "100"p = "1"print("you have ", p, " potions")print("Your health is ", health,)while True: a = input("A =") if a == "add": health = int(health) p = int(p) + 1 print("you have ", p, " potions") print("Your health is ", health,) a = input("A =") if a == "fight": q[1] #random.choice(q)
添加回答
举报
0/150
提交
取消