python - Python行没有运行
问题描述
while True:
inp = raw_input()
if inp == "":pres= input("What would you like to know about me? AGE, JOKE, FACT")
if pres in {'AGE'}:
print("I was birthed from my mother 87 years ago.")
if pres in {'JOKE'}:
print("Where do polar bears keep their money?")
import time
time.sleep(2)
print("In a snow bank!")
if pres in {"FACT"}:
print("Hippopotamus's have pink spit!")
我是一名学生,我的学校项目必须编写代码,由于某种原因,当有人输入 AGE、JOKE 或 FACT 时,我无法弄清楚如何让聊天机器人回答问题。Insteas,当我按下回车键时,它只是重复了这个问题。
解决方案
您在while True
循环中要求输入。它永远不会退出,因为True
……永远是真的。您需要将if
语句放入循环中,以便它们也能执行。
推荐阅读
- java - 如何为 Cockpit 用户禁用 cmscockpit 中的同步按钮?
- python - 如何在列表中排在最后?
- camunda - 有没有办法自定义camunda的rest api?
- java - 如何解决谷歌应用引擎延迟?
- symfony - Symfony 5 LiipImagineBundle 图像未创建到缓存中
- javascript - OIDC - js客户端的正确登录流程
- ios - 更改 StackView 高度时更新 UIView 高度
- c++ - 使用函数式编程,使用 fplus: 转换向量时出错
> 到矢量 > - spamassassin - SpamAssassin规则解释
- javascript - 使用打字稿多次分组到对象中