在Python中,如何在需要之前拒绝输入?

2024-09-26 18:02:21 发布

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

我从代码中摘录了问题仍然存在的地方。我相信这是因为我的slow\u type函数,但是当对话是“slow-typed”时,我的输入将接受在“slow\u type”期间输入的任何值,甚至在输入出现之前。我希望输入只能在slow\u type函数完成后才能输入。我该怎么做?你知道吗

import time
import sys

def slow_type(line, speed):#You input the dialogue and speed(smaller = faster)
    for l in line:
        sys.stdout.write(l)
        sys.stdout.flush()
        time.sleep(speed)
    time.sleep(.5)

NL1 = "Huh, I see you finally came. "
NL2 = "You know I sent you that message a long time ago.\n"
NL3 = "But I guess you are here now, and that's what matters. "
NL4 = "So...\n"
NL5 = "\n\t\t\t\tAre you ready?\n\n"

slow_type(NL1, .05)
slow_type(NL2, .05)
slow_type(NL3, .05)
slow_type(NL4, .2)
slow_type(NL5, .05)

print("\t\t1:Yes, I am. 2:Who are you? 3:No, I am leaving.\n")
first_choice = input("\t\t\t\t    ").lower()

我使用的是windows10cmd。你知道吗


Tags: and函数importyouinputtimetypestdout

热门问题