我正在为家庭作业制作一个简单的游戏。我想打印线条,但让它们彼此间隔 1 秒打印。我该怎么做呢?
我猜会延迟打印的东西。所以喜欢
"Hello"
"My name is blahblah"
"This is blah blah"
"blah blah"
"What's your name?"
time.sleep(seconds)
暂停一秒钟,在你的情况下:
import time
strings = ["Hello","My name is blahblah","This is blah blah","blah blah","What's your name?"]
for txt in strings:
print txt
time.sleep(1)
您可以使用time.sleep(1)
1 秒延迟
import time
while(1):
print("-")
time.sleep(1)
# coding:utf-8 -*-
import time
def print_line(lines):
"""
print every line in lines per 1s
"""
assert type(lines) in (list, tuple, str)
if type(lines) == str:
lines = (str,)
for line in lines:
print line
time.sleep(1)
if __name__ == "__main__":
"""test print line with a simple tuple"""
test_data = "Hello", "My name is blahblah", "This is blah blah","blah blah","What's your name?"
print "print one sentence per second, begin ..."
print_line(test_data)
print "finished!"