如果你关心的是输入是一个有效的数字文字,甚至不要打扰正则表达式. int将正确解析字符串或引发异常.
int
while True: s = input("Please enter a number: ") try: n = int(s) break except ValueError: print("Error! Make sure you only use numbers") print("You picked number " + n)