import random
import time
import sys
def delay_print(s):
for c in s:
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(0.25)
delay_print("Hello Evelyn!")
greetings = ['hola', 'hello', 'hi', 'Hi', 'hey!','hey']
random_greeting = random.choice(greetings)
question = ['How are you?','How are you doing?','how are you','whats up','Whats up']
responses = ['Okay',"I'm fine"]
random_response = random.choice(responses)
question1 =['whats the time?','whats is the time?','whats the time','what is the time']
watch =("TIME TO GET A WATCH!")
question2 =['whats the weather','what is the weather','whats the weather for today','whats the weather today']
weather =("THE STUFF OUTSIDE!!")
question3 =['how did you know my name','how did you know what i was called']
name =("Because I named you!")
question4 =['whats your favorite color','whats your favorite colour']
color =("Red!")
question6 =['what does the fox say','what did the fox say']
fox =("Ring ding ding ding dingeringeding Gering ding ding ding dingeringeding Gering ding ding ding dingeringeding")
while True:
userInput = input(">>> ")
if userInput in greetings:
print(random_greeting)
elif userInput in question:
print(random_response)
elif userInput in question1:
print(watch)
elif userInput in question2:
print(weather)
elif userInput in question3:
print(name)
elif userInput in question4:
print(color)
elif userInput in question6:
print(fox)
else:
print("I did not understand what you said")
我正在尝试编写聊天机器人代码。我有延迟写作工作正常。我无法弄清楚如何让代码在之后开始新的一行 每个问题!
所以它说 你好Evelyn 回答应该是问题后的新线。所以在延迟文本打印后,它应该向下移动一行并等待用户输入答案
这是我第一次在stackover流程上也很温柔
答案 0 :(得分:0)
在\n
delay_print()
实施例: delay_print(“Hello Evelyn!\ n”)