The normal approach, I found online, to ensure the correct type of user input is as the code below.
if not isinstance(amount, int):
raise ValueError("Please enter an integer as amount.")
else:
return amount
I wrapped the above code in a function and then called the function with the parameter. I personally prefer to put it in a function. Is it an acceptable variation to check the user input? (in a class)
def __init__(self, amount):
def check_userinput(amount):
if not isinstance(amount, int):
raise ValueError("Please enter an integer as amount.")
else:
return amount
self.amount = check_userinput(amount)