我正在尝试使第一个函数 opt1() 使健康下降 50 点,但是由于某种原因它不起作用。该代码在不在函数中时有效。不起作用的行: health = int(health) - 50import randomhealth = "100"p = "1"def opt1(): print("Du förlorade striden") health = int(health) - 50 print(health)def opt2(): print("hej2")def opt3(): print("hej3")q = [opt1, opt2, opt3]ind = random.randint(0,len(q)-1)print("you have ", p, " potions")print("Your health is ", health,)while True: print("Commands: Add, drink, sleep, fight, quest") a = input("Enter a command: ") if a == "add": health = int(health) p = int(p) + 1 print("you have ", p, " potions") print("Your health is ", health,) if a == "fight": q[ind]()
添加回答
举报
0/150
提交
取消