我正在嘗試使第一個(gè)函數(shù) opt1() 使健康下降 50 點(diǎn),但是由于某種原因它不起作用。該代碼在不在函數(shù)中時(shí)有效。不起作用的行: 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]()
2 回答

猛跑小豬
TA貢獻(xiàn)1858條經(jīng)驗(yàn) 獲得超8個(gè)贊
def opt1():
在 opt1 中,您應(yīng)該聲明您提供給函數(shù)的變量。
例如:
def opt1(health):
添加回答
舉報(bào)
0/150
提交
取消