已知有play()函数可以播放动画片,请使用装饰器给其添加权限,只有年龄在1-10岁之间可以正常播放。
def perm(play):
def foo(age):
if 1 < age and age < 10:
play(age)
else:
print("你已经长大了,小孩子才看动画片!")
return foo
@perm
def play(age):
print("{}岁小朋友可以看动画片!".format(age))
play(9)
def perm(play):
def foo(age):
if 1 < age and age < 10:
play(age)
else:
print("你无权限看动画片!")
return foo
@perm
def play(age):
print("{}岁小朋友可以看动画片!".format(age))
if __name__ == '__main__':
a = int(input("请输入年龄:"))
play(a)