如何允许IF语句接受两个或多个变量

时间:2017-07-22 03:19:48

标签: python

        # 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!")

当用户输入“Attack”时,将打印该消息,但是如果用户输入“attack”则会继续请求UserAction而不是打印消息。如何允许IF语句接受两个或更多替代字符串?

1 个答案:

答案 0 :(得分:0)

您可以将值转换为小写,然后只进行一次比较。

if UserAction.lower() == "attack":