矩形面积和周长
# -*- coding: utf-8 -*-
''' 静态方法 计算矩形面积和周长'''
class jingt:
#使用装饰器@staticmethod,声明此为静态方法
@staticmethod
def perimeter(long,wide):
# 编写周长计算逻辑
try:
return 2 * (long + wide)
except:
return f'周长计算参数不对{long , wide}'
@staticmethod
def area(long,wide):
# 编写面积计算逻辑
try:
return long * wide
except:
return f'面积计算参数不对{long,wide}'
if __name__ == '__main__':
print(f"周长为{ jingt.perimeter(10,5)} ")
print(f"面积为{ jingt.area(10,5)} ")