我已在我的代碼中包含驗證,以確保只能輸入一個數字。但是,如果輸入負數,負數不會被程序接受爲有效輸入。我該如何解決這個問題?該代碼是:驗證數據類型檢查是否與預期相反?
while QuestionNo != 11:
num1 = randint(0,10)
num2 = randint(0,10)
opp = choice(Operators)
Answer = (input(str(num1) + '' + (opp) + '' + str(num2) + '='))
while Answer.isdigit() == False:
print ('Please enter a number and nothing else.')
Answer = (input(str(num1) + '' + (opp) + '' + str(num2) + '='))
感謝, 約翰·史密斯
的[我如何檢查字符串是否是一個數字(浮動)在可能的複製Python?](http://stackoverflow.com/questions/354038/how-do-i-check-if-a-string-is-a-number-float-in-python) –