import time,sys
def getinput(question):
text = input(question)
for x in text:
sys.stdout.write(x)
sys.stdout.flush()
time.sleep(0.00001) #Sets the speed of typing, depending on your system
text = 'What is your name? '
for x in text:
sys.stdout.write(x)
sys.stdout.flush()
time.sleep(0.00001)
name = input()
您还可以随机化每个循环的睡眠时间,以便更好地模拟键入,如下所示:
import time,sys,random
text = 'What is your name? '
for x in text:
sys.stdout.write(x)
sys.stdout.flush()
time.sleep(random.uniform(.000001, .000019))
name = input()
import time,sys,random
text = 'What is your name? '
for x in text:
print(x, end="", flush=True)
time.sleep(random.uniform(.000001, .000019))
# or smaller sleep time, really depends on your system:
# time.sleep(random.uniform(.01, .5))
name = input()
您可以使用以下代码:
现在每次调用
getinput("Sample Question")
,都会根据传递给函数的问题得到用户的输入。你知道吗您可以使用:
您还可以随机化每个循环的睡眠时间,以便更好地模拟键入,如下所示:
正如Tomerikoo指出的,有些系统有更快/较慢的延迟,因此您可能需要在另一个系统上使用统一的(.01,.5)。我使用OS/X
在windows上,这可能效果更好。感谢Tomerikoo:
相关问题 更多 >
编程相关推荐