Relative Content

Tag Archive for pythonterminalprintingsys

Why my code prints multiple same lines when it reaches the end of terminal?

import time import sys def animate_string(input_string, delay_second=0.01): current_string = “” for target_char in input_string: if target_char == ‘n’: # Print a newline and reset current_string print() current_string = “” continue current_char = ‘a’ while current_char != target_char: a_code = ord(current_char) # previous string + current letter sys.stdout.write(‘r’ + current_string + current_char) sys.stdout.flush() time.sleep(delay_second) # Move […]