Guardian
Sun Jan 30 2022 11:40:11 GMT+0000 (Coordinated Universal Time)
Saved by
@marcpio
# coditions may act as guardians, protecting the coe that follows from values that might cause an error
# Ex: factorial() can only take positive integers, n:
def factorial(n):
if not isintance(n, int):
print("n has to be an integer!")
return None
elif n < 0:
print("n has to be positive number!")
return None
elif n == 0:
return 1
else:
return n * factorial(n-1)
content_copyCOPY
Comments