Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
1

How to print 1 letter at a time.

OldWizard209
OldWizard209

Hi, I want to print one letter at a time with an interval of 0.3 seconds on the same line. How am I supposed to implement it in my program. I appreciate your kind help.

2 years ago

Voters

Comments

TopNew
3
RYANTADIPARTHI
RYANTADIPARTHI

You could do it this way:

import time import sys import os for x in ("YOUR TEXT"): sys.stdout.write(x) sys.stdout.flush() time.sleep(0.3)

So this will work, you can set the time equal to your accordance. write your sentence where I put your text.

2 years ago
2
OldWizard209
OldWizard209

Thanks

@RYANTADIPARTHI
. It worked As always Thanks a lot.

BTW you answered first this time soo good luck with your 5 new cycles :)

2 years ago
2
OldWizard209
OldWizard209

Nope. Thanks to you . You earned it

@RYANTADIPARTHI

2 years ago
1
Bookie0
Bookie0

make it into a function

@RYANTADIPARTHI

2 years ago
1
Bookie0
Bookie0

I wrote a comment with how to do it

@abdullahrajput9

2 years ago
2
Bookie0
Bookie0

Hi,

here is a better way of doing it:

First the imports:

import sys, os import time

And this is the code:

st = 0.03 def sp(str): for letter in str: sys.stdout.write(letter) sys.stdout.flush() time.sleep(st) print()

I usually put it at 0.04 because it prints it not too fast and not too slow. But you can change it. Just change the value after st

Each time you want to do this typewriter effect, just do:

sp(“Hello World”)

Output:

Hello World

(outputted one char at a time)

this is from my tutorial here ;)

2 years ago
2
OldWizard209
OldWizard209

OH Thanks a lot for the help

@Bookie0
I will try this method. But sorry I couldn't mark your answer. :)

2 years ago
2
Bookie0
Bookie0

np lol :D

@abdullahrajput9
putting it in a function is easier so you can use it when you need/want to! :)

2 years ago
1
RYANTADIPARTHI
RYANTADIPARTHI

@Bookie0
well, i guess this is good, but I did it in fewer lines of code. That matters.

2 years ago
1
Bookie0
Bookie0

@RYANTADIPARTHI
but then to use it several times...?

2 years ago
2
adsarebbbad
adsarebbbad
import time, sys from time import sleep def sp(str): for letter in str: sys.stdout.write(letter) sys.stdout.flush() time.sleep(0.06) print()

from here

2 years ago
2
OldWizard209
OldWizard209

Thanks a lot

@adsarebbbad
I am sorry I can't mark your answer because
@RYANTADIPARTHI
answered first :)

2 years ago
Load more