How to print a text string with pauses between each letter printed in python 3.4?

2

Suppose I have string="I still find the guy funny" I want the result to be I still find the guy funny but that after each letter a small pause is made

I thought about the code

for letra in cadena:
   print(letra, end="")
   time.sleep(0.3)

but the result is

  

a

     

u

     

n

     

m

     

e

     

p

     

a

     

r

     

e

     

c

     

e

     

g

     

r

     

a

     

c

     

i

     

or

     

s

     

or

     

e

     

l

     

c

     

h

     

a

     

v

     

or

How can I make it print on the same line with time pauses after each letter?

    
asked by jose.gb89 03.10.2016 в 16:48
source

2 answers

3

This form can help.

from time import sleep
import sys

text = "aun me parece gracioso el chavo"
for c in text:
    print(c, end='')
    sys.stdout.flush()
    sleep(0.5)

demo

    
answered by 03.10.2016 / 16:52
source
0

No need to use the sys module

from time import sleep

text = "aun me parece gracioso el chavo"
for i in range(len(text)):
    print(text[0:i], end="\r")
    sleep(0.5)
print(text, end="\r")

To highlight the use of \r in the function print . \r takes the print to the beginning of the same line.

    
answered by 03.10.2016 в 17:33