[PYTHON 3.8] Carriage return occurring for no reason

When working on my adventure game (Link: https://replit.com/@IsaacIsAwesome/StudiousReflectingConditional?v=1) I noticed that sometimes the cursor would return to the beginning of the line for no reason when printing something. It only occurs for some print statements which made me confused.

To replicate the bug, follow these steps:

  1. Hit Run.
  2. Enter “2” to access the Pack.
  3. Enter “3” or “4” to consume an Antidote and cure the player’s Poison.

At this point, you’ll notice that the screen displays this:

Poison! sted an Antidote and were cured of your

I think this occurs because this is printed to the console first:

You ingested an Antidote and were cured of your

And then a carriage return happens for some reason and overwrites the beginning part:

Poison! sted an Antidote and were cured of your

If someone knows why this is happening, I greatly appreciate it. Thanks for taking the time to read this!

Hi @IsaacIsAwesome thanks for your question and welcome to the community.

I really like your game! Great use of colour too which makes it more appealing to the user.

I managed to replicate your issue and narrowed down the problem to the following line 192:

I changed the input to a print command and then placed a blank input() on the next line. This resolved the issue.

Thank you, that’s a clever solution. I’ll do that for all of the other instances of this bug. Do you have any idea why this is occurring?

No problem. I do not know why this is happening but wonder if the same thing would happen if run in VSCode or IDLE.

probably because input uses the stderr stream, so it’s buffered separately to stdout which is used by print.
Also, maybe check out f-strings instead of using + repeatedly