Reputation: 1152
I'm making a simple game for homework. I would like to print lines, but have them print 1 second apart from each other. How would I go about doing that?
Something that would delay the prints I guess. So like
"Hello"
"My name is blahblah"
"This is blah blah"
"blah blah"
"What's your name?"
Upvotes: 1
Views: 141
Reputation: 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!"
Upvotes: 0
Reputation: 2806
time.sleep(seconds)
pauses for a second, in your case:
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)
Upvotes: 5