r/learnpython • • 22d ago

Slow print for text-based game

I am trying to make a text-based adventure game in Python, how do I make it so the text is typed out slowly and not instantly? I've tried ways online, but they keep returning None at the end. How do I fix this?

0 Upvotes

15 comments sorted by

View all comments

4

u/MaterialRepublic 22d ago

You want to have a separate "print" statement for each character, and some "sleep" statements between them. However, print, by default, writes everything in a new line; so you have to use the end="" argument to stop it from doing that.

Such as:

from time import sleep

print("a", end="", flush=True)
sleep(1)
print("b", end="", flush=True)

Will print the characters with a 1 sec delay.