Can I overwrite in Python 3?

Is there a way I can make a text which overwrite each other during the execution of a program:
Like If I want to create a program which chooses between Heads or Tails, I want during the execution of the program if I choose Head, then there will be a bit of animation like Head and tails text overwriting each other really quickly and I get the answer, I don’t know if you guys understand what I meant, cause I don’t know how to even Google that? :thinking:

Do you mean ‘HEADS’ and ‘TAILS’ printed to the screen rapidly? That’s quite easy but will probably print really fast without some explicit waiting added.

If this is for a webpage, you could just use some simple animation or gif. If it’s for the console, why bother?

1 Like

You could make it wait with the sleep function from the time module.

Yeah @florian I did something similar in this green screen sim:

Iirc I think the parameters have changed in 3.8 so time is ms not sec. which is more standard.

I think @gpkesley has a good solution, but you just use \r to make the cursor go to the column 0 of the line, then overwrite it. I think I have a tiny bit of code in the book that does this as a joke to make a spinner on the terminal.