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) 一樣改變你的代碼
添加回答
舉報