For practice, I’m trying to do some stuff in Python. I’ve decided to make a simple hangman game – I’m not making a GUI. The game would start with a simple input(). Now, I’d like next line to, beside asking for input, to delete the hidden word. I’ve tried using \b (backspace character), but it’s not working. Something like:
word = input("Your word: ")
for i in range(len(word) + 12):
print("\b")
Now, printing the backlash character is supposed to delete the input and “Your word”, but it isn’t doing anything. If I do this in IDLE I get squares, and I get nothing if I open it by clicking.
How to accomplish this? I’m afraid I wasn’t too clear with my question, but I hope you’ll see what I meant. 🙂
I assume the player entering the word wants to be sure they’ve entered it correctly so you probably want to display the word as they’re typing it right?
How about printing enough
\ns to move it off the screen when they’re done or issue a clear screen command?You mentioned this was a simple game so a simple solution seems fitting.
[Edit] Here’s a simple routine to clear the console on just about any platform (taken from here):