I'm writing a program that ask for users input and check if it is an integer. If yes than it converts it into an integer and return with the value. If the user typed something which isn't a number than the program ask the user again to input a number. If the user press only an enter and keep the input empty than it will return with a default value.
def inputNumber(message):
number = input(message)
if number !='':
if number.isdigit():
number = int(number)
return number
else:
print("This is not a whole number! Try again.")
inputNumber(message)
else:
number = int(1000)
return number
The program works well until I write a letter. If I write for example 'x' than it will say try again:
Max cooldown(secs): x
This is not a whole number! Try again.
Max cooldown(secs):
But if I press an enter with empty input it will not return with the default value but with None. It is only happens when I make an error with writing a letter.