def getInput(): while True: if (x := input()).isdigit(): print(x) break getInput()
运行效果:
注:Python3.8新增了:=运算符,可以用赋值语句替代