# function that prints hello your name is x and you are y years old
# name must be of type string and cannot be empty
# age must be of type int and cannot be 0
def functionX(name, age):
if name == "":
raise ValueError("name cannot be empty")
if not isinstance(name, str):
raise TypeError("name seem not to be a string")
if age == 0:
raise ValueError("age cannot be 0 (zero)")
if not isinstance(age, int):
raise TypeError("age needs to be an integer")
print("hello ", name, ", you seem to be ", age," years old")
Is this a correct way of checking parameters provided to a function?
isinstance()checks. ValueError is for the correct type but incorrect valuemypyto perform a static analysis.printcall will only care thatstr(name)andstr(age)don't raise exceptions. The empty string and0can both be printed just fine.