def set_age(name, age):
if not 0 < age < 120:
raise ValueError('年龄超过范围') # 自主决定触发什么样的异常
print("%s is %d years old" % (name, age))
def set_age2(name, age):
assert 0 < age < 120, '年龄超过范围' # 断言异常
print("%s is %d years old" % (name, age))
if __name__ == '__main__':
set_age('zhangsan', 20)
set_age2('lisi', 200)