1

我正在为家庭作业制作一个简单的游戏。我想打印线条,但让它们彼此间隔 1 秒打印。我该怎么做呢?

我猜会延迟打印的东西。所以喜欢

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

4 回答 4

5

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)
于 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 回答