1

宿題用の簡単なゲームを作っています。ラインを印刷したいのですが、1秒間隔で印刷してください。どうすればそれを行うことができますか?

私が推測するプリントを遅らせる何か。以下のようなので

"Hello"
"My name is blahblah"
"This is blah blah"
"blah blah"
"What's your name?"
4

4 に答える 4

5

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)
于 2012-09-26T01:14:19.850 に答える
0

time.sleep(1)1秒の遅延を与えるために使用できます

于 2012-09-26T01:14:35.793 に答える
0
import time

while(1):
    print("-")
    time.sleep(1)
于 2012-09-26T01:15:56.057 に答える
0
# 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!"
于 2012-09-26T01:31:08.527 に答える