如何从字符串中检测多个单词? (python)
How can I detect multiple words from a string? (python)
我需要创建一个程序,用户可以在其中输入他们遇到的 phone 问题。由于回复可能是多个单词和行,我需要能够从回复中提取关键短语和单词,例如 "doesn't turn on" 或 "cracked"。到目前为止,我尝试过的一切都没有奏效;不是真正的编程专家,最近才开始。
伪代码:
x=input("What is wrong with your phone?")
if "dropped" in x:
print( #text )
我正在使用 Python v3.
提前谢谢你。
这是一个方法:
x = input("What is wrong with your phone?")
keywords = ["doesn't turn on", "cracked", "dropped"]
if any(keyword in x for keyword in keywords):
print("test")
您可以使用 split()
然后 in
例如:
response = input("What is wrong with your phone?")
responseList = response.split()
if "dropped" in responseList:
#print( #text )
您输入的验证码没有问题。
x = input("What is wrong with your phone?")
if "dropped" in x:
print("You've dropped your phone!")
我需要创建一个程序,用户可以在其中输入他们遇到的 phone 问题。由于回复可能是多个单词和行,我需要能够从回复中提取关键短语和单词,例如 "doesn't turn on" 或 "cracked"。到目前为止,我尝试过的一切都没有奏效;不是真正的编程专家,最近才开始。
伪代码:
x=input("What is wrong with your phone?")
if "dropped" in x:
print( #text )
我正在使用 Python v3.
提前谢谢你。
这是一个方法:
x = input("What is wrong with your phone?")
keywords = ["doesn't turn on", "cracked", "dropped"]
if any(keyword in x for keyword in keywords):
print("test")
您可以使用 split()
然后 in
例如:
response = input("What is wrong with your phone?")
responseList = response.split()
if "dropped" in responseList:
#print( #text )
您输入的验证码没有问题。
x = input("What is wrong with your phone?")
if "dropped" in x:
print("You've dropped your phone!")