Making Typewriter Wait Between Line

Question:
Is there a way to make it wait a little bit between the new lines like after it finishes one it’ll wait about a second to then do the next line?
What It Does Now:

Code:

    for char in text:
        sys.stdout.write(char)
        sys.stdout.flush()
        time.sleep(delay)

if __name__ == "__main__":
    intro = "Rock Paper Scissor Battle!\nYou will type rock paper or scissors and you will fight a computer\n"
    typewriter_print(intro)

while True:
  computer = random.randint(0,3)
  p1 = '\nROCK! PAPER SCISSORS SHOOT!\n'
  typewriter_print(p1)
  person = input('\tPlay:\t')

You can make an if statement to check if char is “\n”. If it is, then add something to the delay.

Also, the code is a bit cut off. A Repl link would help more :slight_smile:

Hope this helped!

3 Likes

https://replit.com/@Chandler0Bing/Rock-Paper-Scissors-Vs-A-Computer#main.py

Sorry abt that

Code:

def typewriter_print(text, delay):
    for char in text:
        sys.stdout.write(char)
        sys.stdout.flush()
        time.sleep(delay)
        if char == "\n":
            time.sleep(0.5) # you can write any number here
1 Like

You can also use print if you’d like.

from time import sleep
text = '''Welcome!
This is a typewriter.
You will watch in awe as it types.
The end.'''
def typewriter(text, char_delay, paragraph_delay):
  for line in text.split("\n"):
    for char in line:
      print(char, end="", flush=True)
      sleep(char_delay) # time in seconds
    print()
    sleep(paragraph_delay) # delay after every new line
typewriter(text, 0.06, 1)
3 Likes

Intentionally didn’t write the code; I don’t want to spoon-feed.

3 Likes

Thanks for all the help y’all

3 Likes

Hey, um, didn’t I already answer this in another topic you created? If you needed help, you could’ve just asked me to change the delay instead of creating a new topic.

2 Likes

I was asking about how to get it to wait before going onto the next line. If you said it in the last post I didn’t see it sorry.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.