2 回答

TA贡献1802条经验 获得超10个赞
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 step== "stand"):
stand()
elif (step == "Hit" or step=="hit"):
hit()
elif (step == "Double down" or step=="down"):
doubledown()
else:
step()
step()
问题在于 if 语法。

TA贡献1785条经验 获得超4个赞
因为在这里错误地使用了 if 语句,例如“if step == ("Hit") or ("hit"):” python 将执行 step==("Hit") 并且根据用户输入结果为 False 或 True但它跟随字符串“hit”python 会像 True 一样读取它,所以最后,它就像“if (step==(“Hit”)) or (True) ,那么你的每一个 if 语句都会被执行,因为逻辑上是 True !
你应该像 if (step==sth) 或 (step==sth) 一样改变你的代码
添加回答
举报