If you dig around, you'll find various versions of something called getch. This uses code from py-getch:
import sys try: from msvcrt import getch except ImportError: def getch(): import tty import termios fd = sys.stdin.fileno() old = termios.tcgetattr(fd) try: tty.setraw(fd) return sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old) ascii_numbers = [ord('0') + x for x in range(10)] weight = 0.0 while True: message = f"Enter your weight: {weight:9.2f} (kg)" sys.stdout.write("\r" + message) sys.stdout.flush() c = ord(getch()) if c == 13: break elif c in ascii_numbers: c = c - ord('0') weight = (weight * 10) + (float(c) / 100) elif c == 127: weight = weight / 10 print("")
This is ugly, but my last experience with ncurses was even uglier.
Warning
This program ignores Ctrl-C inside the getch call. It is possible to modify this code so that the only way to stop the program is to kill the process. Sorry.
print("aaaaaaaaaaaaaa\r\tbb")-\ris \carriage return\ which gets you back to the beginning(!) of the current line,\tis a tab character.weight = float(input('Enter your weight (kg): '))?(kg)on left before:-Enter your weight (kg): some_number.