What does “\r” do in the following script?

The ‘\r’ character is the carriage return, and the carriage return-newline pair is both needed for newline in a network virtual terminal session. From the old telnet specification (RFC 854) (page 11): The sequence “CR LF”, as defined, will cause the NVT to be positioned at the left margin of the next print line (as would, for example, the … Read more

pygame.error: video system not initialized

You should stop your main loop when you want to exit the game. My suggestions, either of call exit() after pygame.quit() set finish = True and start = False (though due to some indentation issues with your pasted code it’s not possible to tell that this would actually work) You should call pygame.quit() only when you want to terminate your Python session. My suggestion: … Read more

Remove all whitespace in a string

If you want to remove leading and ending spaces, use str.strip(): If you want to remove all space characters, use str.replace(): (NB this only removes the “normal” ASCII space character ‘ ‘ U+0020 but not any other whitespace) If you want to remove duplicated spaces, use str.split():