简体   繁体   English

如果我的答案包含某些内容,我该如何做出if陈述

[英]How do i make an if statement if my answer includes something

i am a fairly average coder and i would love to know that if my player says something rand but it includes keywords it would still do a if statement? 我是一个相当普通的编码器,我很想知道,如果我的播放器说的是兰德,但它包含关键字,它仍然会执行if语句?

For example. 例如。 Answer = input("Take lantern or leave") if answer ==(Includes like "Pickup" instead of take i want this to still run or if they say pickup the lantern etc. 答案=输入(“带灯笼或离开灯笼”),如果答案==(包括类似“提货”的提示,而不是我希望它仍然运行,或者他们说拿灯笼等)。

I hope you can help me, if any additional info needed just ask 希望您能为我提供帮助,是否需要其他信息

print ("You can barley see anything around you but can hear loud noises coming from within the cave") print ("") answer = input (" There is a blue door onfront of you, beside you, beside you is a lantern of which is rusty but working ") 打印(“大麦可以看到你周围的任何东西,但可以听到洞穴内传来的巨响”)打印(“”)答案=输入(“你前面有一个蓝色的门,在你的旁边,旁边是一个灯笼生锈但可以正常工作“)

 if answer == "take lantern" or answer == "Take lantern":

I want it so they don't have to precisely put "Take lantern or something like that, i want keywords like "Pickup" or "Take" 我想要这样,所以他们不必精确地输入“拿灯笼或类似的东西,我想要像“皮卡”或“拿”这样的关键字

You could either check if your answer is in a list of expected answers: 您可以检查您的answer是否在预期答案列表中:

answer = input("...")
if answer in ["take", "pickup"]:
    ...

Or you could check your answer with Regular Expressions: 或者,您可以使用正则表达式检查answer

import re
...

if re.search("(take|pickup)", answer):
    ....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何让我的 if 语句真正做某事 - How do I make my if statement actually do something 如何刷新我的代码以便为调查做出新答案? - How do I refresh my code to make a new answer for the survey? 我如何做出 discord 机器人回答? - How do i make a discord bot answer? 如何使我的代码在我的一个 function 中包含两个“while”循环? - How do I make it so my code includes both "while" loops in my one function? 如何从列表中随机生成 python select 某些内容,如果在输入提示中键入,它将按预期显示确切答案 - How do I make python randomly select something from a list and if typed in the input prompt, it will show the exact answer as intended 当用户回答错误时,如何使我的代码不生成新的整数? - How do I make my code not generate new integers when the user gets the answer wrong? 我怎样才能让我的 discord 机器人按顺序提问和回答? - How do I make it so my discord bot will ask and answer in an order? 如何让我的 Discord Bot 对列表中的不同单词回复相同的答案? Python - How do I make my Discord Bot reply a same answer to different words from a list? Python 我如何让我的机器人判断给出的数字是高于还是低于答案? [不和谐.py] - How do I make my bot tell if the number given was higher or lower then the answer? [discord.py] 如何编写包含 : 和 % 的 SQL Like 语句? - How do I write a SQL Like statement that includes : and %?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM