I'm trying to modify the existing input function in a project just so that it can loop if the input given is not an integer, but I can't seem to find out how.
If this is a normal function it works:
def getInput():
while True:
try: x = int(input()); break
except ValueError: print("Number not integer. Try again.")
return x
numberOfNodes = getInput()
I've thought of changing this to def __input__():
but it does not modify the built-in function. Is there a way to re-write built-in functions? This piece of code is pretty much all I need but I was just curious to see if I can make it the default behavior for input.