반응형
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
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1015. simple calculator (0) | 2022.10.15 |
---|---|
1014. Find Multiples of a Number (0) | 2022.10.14 |
1012. All Star Code Challenge #18 (0) | 2022.10.12 |
1011. Square(n) Sum (0) | 2022.10.11 |
1010. Double Char (0) | 2022.10.10 |