python - if 语句中的多个 if 语句都依赖于输入?
问题描述
我的目标是让每个输入激活每个打印当前代码:
import time
P = 95
west = 'west'
north = 'north'
south = 'south'
east = 'east'
lamp = 'lamp' 'light fixture' 'lamp'
grab = 'grab', 'get,', 'retrive','take'
go = 'go', 'tavel', 'walk', 'run'
put_down = 'place', 'drop', 'put'
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#*similarity functions*#
from difflib import SequenceMatcher
def similar(a, b):
return SequenceMatcher(None, a, b).ratio()
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#print("wait for it")
#time.sleep(10)
#print("i just wasted 10 seconds of your life")
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++#
def lampIn(stat):
return 'lamp' in stat or 'light fixture' in stat
def grabIn(stat):
return 'grab' in stat or 'get,' in stat or 'retrive' in stat or 'take' in stat
def westIn(stat):
return 'west' in stat
def northIn(stat):
return 'north' in stat
def southIn(stat):
return 'south' in stat
def eastIn(stat):
return 'east' in stat
def grabIn(stat):
return 'grab' in stat or 'get' in stat or 'retrieve' in stat or 'take' in stat
def goIn(stat):
return 'go' in stat or 'travel' in stat or 'walk' in stat or 'run'
def put_downIn(stat):
return 'place' in stat or 'drop' in stat or 'put' in stat
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++#
while True:
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++#
statement = input()
statement = statement.lower()
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++#
resultGrab = similar(grab, statement)
grabResult = grabIn(statement)
for grabResult in statement or resultGrab >= P:
print("what are you getting?")
#+++++++++++++++++++++++++++++++++++++++++++++++++++++#
statement = input()
statement = statement.lower()
#+++++++++++++++++++++++++++++++++++++++++++++++++++++#
resultLamp = similar(lamp, statement)
lampResult = lampIn(statement)
for lampResult in statement or resultLamp >= P:
print("you now have the lamp")
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++#
resultGo = similar(go, statement)
goResult = goIn(statement)
for goResult in statement or resultGo >= P:
print("Where?")
#+++++++++++++++++++++++++++++++++++++++++++++++++++++#
statement = input()
statement = statement.lower()
#+++++++++++++++++++++++++++++++++++++++++++++++++++++#
resultWest = similar(west, statement)
westResult = westIn(statement)
for westResult in statement or resultWest >= P:
print("You went west.")
else: print("not a command yet")
结果:
>>>walk
what are you getting?
est
you now have the lamp
you now have the lamp
you now have the lamp
you now have the lamp
what are you getting?
我试图达到的结果:
>>>walk
where?
west
you went west
同时还维护每个单独的路径
解决方案
推荐阅读
- html - 不知道为什么这两个 div 重叠?
- python - 在 python 中编辑文本文件并创建一个新文件
- c++ - c++:如何在 sprintf 连接中插入换行符?
- php - SwaggerUI 不为参数生成名称属性
- java - 我可以使用 Java 在另一个枚举中添加枚举吗?
- google-sheets - 与不同的工作表相比,突出显示具有唯一值的行
- sml - SMLNJ:运算符和操作数不同意 [tycon mismtach] - 用于列表分配
- java - Java socket/JavaFX - 发送 mssgs 使客户端停止工作
- javascript - 如何优化此同步“模糊搜索”功能并将其转换为异步功能?
- python - 如何有效地找到二维矩阵中多个元素的行索引?