나는 이렇게 학습한다/Algorithm & SQL
1013. Area or Perimeter
daco2020
2022. 10. 13. 22:39
You are given the length and width of a 4-sided polygon. The polygon can either be a rectangle or a square. If it is a square, return its area. If it is a rectangle, return its perimeter.
Example(Input1, Input2 --> Output):
6, 10 --> 32
3, 3 --> 9
Note: for the purposes of this kata you will assume that it is a square if its length and width are equal, otherwise it is a rectangle.
Solution:
def is_square(func):
def wrapper(l, w):
return func(l, w, l==w)
return wrapper
@is_square
def area_or_perimeter(l , w, is_square):
return is_square and l*w or (l+w)*2