Python 如何允许IF语句接受两个或多个变量
当用户输入“攻击”时,将打印消息。但是,如果用户输入“攻击”,if将继续请求用户操作,而不是打印消息。如何允许IF语句接受两个或多个可选字符串?您可以将值转换为小写,然后只进行一次比较Python 如何允许IF语句接受两个或多个变量,python,Python,当用户输入“攻击”时,将打印消息。但是,如果用户输入“攻击”,if将继续请求用户操作,而不是打印消息。如何允许IF语句接受两个或多个可选字符串?您可以将值转换为小写,然后只进行一次比较 # Battle Loop while Battle == 1: # Taking users action to decide what to do UserAction = input("Attack, defend, run: ") #
# Battle Loop
while Battle == 1:
# Taking users action to decide what to do
UserAction = input("Attack, defend, run: ")
# If the User decides to Attack
if UserAction == "Attack" and "attack":
print("Attacking!")
如果UserAction.lower()=“Attack”,则执行如果UserAction.lower()=“Attack”:使用UserAction.lower()=“Attack”
if UserAction.lower() == "attack":