我正在尝试制作一个简单的二十一点游戏,我希望能够创建自己的功能,这已经可以做到,然后将其放在 if 语句中,以便如果用户想要“站立”,则它运行该功能“站立”。但是,当 python 读取代码时,即使用户说“命中”,它也会看到所有函数并运行所有函数。
def stand():
print("You have chosen to Stand")
#my stand code will go here
def hit():
print("You have chosen to Hit")
#my Hit code will go here
def doubledown():
print("You have chosen to Double Down")
#my Double Down code will go here
def step():
step = input("What would you like to do now? Stand, Hit or Double Down")
if step == ("Stand") or ("stand"):
stand()
if step == ("Hit") or ("hit"):
hit()
if step == ("Double down") or ("down"):
doubledown()
else:
step()
step()
我希望用户能够一次运行 'Hit'、'double down' 或 'stand' 功能 1,而无需所有这些功能都运行。
守候你守候我
九州编程
相关分类