import sys import time import random def slow2print(text:str="Type a string in", delay_time:float=0.05, mistake_frequency:int=30): words = text.split(' ') for i, word in enumerate(words): # Introduce a mistake approximately every 'mistake_frequency' words if i % mistake_frequency == 0 and i != 0: # Add a random word or two as the mistake mistake_word = word + ' ' + ' '.join(random.choice(words) for _ in range(random.randint(1, 2))) for character in mistake_word: print(character, end='', flush=True) time.sleep(delay_time) time.sleep(2) # pause for 2 seconds after making a mistake # Delete the incorrect characters one by one at half speed for _ in range(len(mistake_word) - len(word)): # delete up to the original word length, excluding the space print('\b \b', end='', flush=True) # backspace to delete the character time.sleep(delay_time * 2) # delete at half speed print(' ', end='', flush=True) # ensure a space is printed after each word else: # Print the correct word for character in word: print(character, end='', flush=True) time.sleep(delay_time) print(' ', end='', flush=True) # ensure a space is printed after each word slow2print("Python print function reduced to physical type speed, with occasional errors included which causes the typing animation to pause briefly, then backspace to remove error, before then continuing to type the desired text. \n")