0

I need to use integer validation for my cambbridge international examination. However, I can not use try except or any libaries. Just what is already on python.

Outputs 'None' if I input a non integer first and then a integer, don't know how to fix it.

  global userInput
  userInput='N/A'
  while userInput.isnumeric() == False:
    userInput = input(message)
    if userInput.isnumeric() == False:
      inputNumber("\n\033[34mNot an integer! Try again.\n\033[0m")
    else:
      userInput=int(userInput)
      return userInput

answer=inputNumber('Please input answer that is an integer  ')


print(answer*answer)```
  • When you recursively call `inputNumber()` after an invalid input, *you throw away its return value*. There's no need for the recursive call anyway, as you have a loop that will prompt for input again. – jasonharper Apr 08 '22 at 14:40

0 Answers0