[英]I've defined a function for a string to be written, and then each individual letter to be printed out. But it won't work with an input()
我试图让它在同一行中逐个字母地打印出问题。
import sys
import time
def typing(msg):
for z in msg:
time.sleep(0.04)
sys.stdout.write(z)
sys.stdout.flush()
input(typing('What is your name? '))
output: What is your name?None
您需要更改输入和键入的顺序:
import sys
import time
def typing(msg):
for z in msg:
time.sleep(0.04)
sys.stdout.write(z)
sys.stdout.flush()
typing(input())
试试这段代码。 我相信你不需要sys
模块。
import time
def typing(msg):
print(msg)
for ch in msg:
time.sleep(0.1)
print(ch)
time.sleep(0.1)
message = input('Whatever a message you want here: ')
typing(message)
动作 & Output:
Whatever a message you want here: Python is great
Python is great
P
y
t
h
o
n
i
s
g
r
e
a
t
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.