我想实现一个循环,但我不知道该怎么做

2024-10-05 12:25:18 发布

您现在位置:Python中文网/ 问答频道 /正文

好吧所以。。。在

print("What do you wanna do?")

input1 = input()

if input1 == "Stab this guy" or input1 == "stab this guy":
     print("You stabbed that guy and killed him.")

elif input1 == "Punch this guy" or input1 == "punch this guy":
     print("You punched him...")

我想用这些复杂的输入创建一个循环,所以当你输入一个仍然复杂但没有被提及的输入时,我希望它打印出类似“对不起,没有抓住那个”这样的内容,这样他们就必须重复输入列表中包含的另一个输入,直到他们说出正确的输入为止。在


Tags: oryouinputifthisdowhatprint
1条回答
网友
1楼 · 发布于 2024-10-05 12:25:18

在已有的基础上:

print("What do you wanna do?")

input1 = input()

complex_inputs = ["stab this guy", "punch this guy"]

while input1.lower() not in complex_inputs:
    print("Sorry didn't catch that")
    print("What do you wanna do?")
    input1 = input()

if input1 == "Stab this guy" or input1 == "stab this guy":
    print("You stabbed that guy and killed him.")

elif input1 == "Punch this guy" or input1 == "punch this guy":
    print("You punched him...")

编辑

要同时处理关键字,这是一个想法:

^{pr2}$

相关问题 更多 >

    热门问题