延迟键入后需要在新行开始文本


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")

我正在尝试编写聊天机器人代码。我的延迟写作工作正常。我只是不知道如何让代码在之后开始一个新行每个问题!

所以它说你好伊芙琳答案应该在问题之后的新行上。因此,在延迟文本打印后,它应该向下移动一行并等待用户输入答案

这是我第一次在堆叠流上也要温柔

delay_print()内传递的参数之后添加一个换行符n

例:delay_print("你好伊芙琳!"(

最新更新