首页 > 解决方案 > 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,当我按下回车键时,它只是重复了这个问题。

标签: python

解决方案


您在while True循环中要求输入。它永远不会退出,因为True……永远是真的。您需要将if语句放入循环中,以便它们也能执行。


推荐阅读