延迟键入需要在新lin上启动文本

2024-06-16 10:33:13 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我正在尝试编写一个聊天机器人。我的写作进度很好。我就是不知道如何让代码在之后开始新的一行 每个问题

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

这是我第一次对叠加流也要温柔


Tags: theinimportyoutimerandomwhatprint