You can use the implementation of getch
to read a single character from the user.
Here is the solution:
import sys
print("Type your age:", end=" ")
sys.stdout.flush()
c = getch()
print(c + " years old")
First, you get:
Type your age: ▯
Then, you press a single character (you can used 2 calls to getch
to get 2 characters).
And it prints:
Type your age: 9 years old
EDIT
But, the classic way to do that, would be:
while True:
try:
age = int(input("Type your age: "))
except ValueError:
print("This is not an integer")
print()
else:
if 1 <= age <= 120:
break
print("please, enter your age between 1 and 120 years")
print()
print("You are {age} years old.".format(age=age))