The python input box can only enter numbers within 10

The input input box can only enter numbers within 10.
Do not record them casually for other purposes.

def inputInt(content='请输入整数:'):
    while True:
        data = input(content)
        try:
            inputData = eval(data)
            if data.isdigit() and type(inputData) == int:
                # break
                return inputData
        except:
            pass
def inputInt1():
    while True:
        user_input = input("请输入数字 1-10:")
        if user_input.isdigit() and int(user_input) in range(1, 10):
            return user_input
            break
        print("输入无效,请重新输入!")


print("你输入的数字是:", inputInt())

Guess you like

Origin blog.csdn.net/qq_20575249/article/details/130780008