宿題用の簡単なゲームを作っています。ラインを印刷したいのですが、1秒間隔で印刷してください。どうすればそれを行うことができますか?
私が推測するプリントを遅らせる何か。以下のようなので
"Hello"
"My name is blahblah"
"This is blah blah"
"blah blah"
"What's your name?"
time.sleep(seconds)
あなたの場合、1秒間一時停止します。
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!"