a = False
while a == False:
quant = int(input("Input the size:\n"))
if type(quant) == int:
a = True
else:
print('Please use numbers:\n')
a = False
Run Code Online (Sandbox Code Playgroud)
我试图让用户无法输入字符,但如果输入,它会打印出第二条消息。但是,当我尝试输入字符时,会出现以下消息:
Traceback (most recent call last):
File "C:/Users/user/Desktop/pythonproject1/Actual Projects/password
generator/Password_generator.py", line 34, in <module>
quant = int(input("Input the:\n"))
ValueError: invalid literal for int() with base 10: 'thisiswhatIwrote'
Run Code Online (Sandbox Code Playgroud)
输入整数时它工作正常。我试过isinstance()and is_integer(),但无法让它们工作,所以只是试图让它变得简单。
python ×1