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.

```
area_or_perimeter(6, 10) --> 32
area_or_perimeter(4, 4) --> 16
```

> 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.

Source: codewars | Difficulty: EASY
Tags: Geometry

Fundamentals

Mathematics

Starter code: def area_or_perimeter(l , w):
	

Solutions:
def area_or_perimeter(l, w):
	return l * w if l == w else (l + w) * 2


area_or_perimeter = lambda a, b: a * b if a == b else 2 * (a + b)


def area_or_perimeter(l, w):
	return [(l + w) * 2, l * w][l == w]


area_or_perimeter = lambda l, w: (l == w) * l ** 2 or (l + w) * 2


def area_or_perimeter(l, w):
	resu = 0
	if l == w:
		resu = l * w
		return resu
	else:
		resu = 2 * (l + w)
		return resu


area_or_perimeter = lambda l, w: l * 2 + w * 2 if l != w else l * w


area_or_perimeter = lambda l, w: [2 * (l + w), l * w][l == w]


def area_or_perimeter(l, w):
	if l == w:
		res = l * w
	else:
		res = l + l + w + w
	return res


area_or_perimeter = lambda l, w: [l + w << 1, l * w][l == w]


def area_or_perimeter(l, w):
	if l == w:
		return l * w
	else:
		return (l + w) * 2
print(area_or_perimeter(6, 10))
print(area_or_perimeter(4, 4))


def area_or_perimeter(l, w):
	if l == w:
		result = l ** 2
		return int(result)
	else:
		result = 2 * (l + w)
		return int(result)


def area_or_perimeter(l, w):
	if l == w:
		polygon = 'square'
		return l ** 2
	else:
		polygon = 'rectangle'
		return l * 2 + w * 2


def area_or_perimeter(length: int, width: int) -> int:
	if length == width:
		return length * width
	return 2 * length + 2 * width


def area_or_perimeter(length, width):
	if length == width:
		return length * width
	else:
		return 2 * (length + width)


def area_or_perimeter(l, w):
	if l == w:
		area = l * w
		return area
	elif l != w:
		perimeter = 2 * (l + w)
		return perimeter
	else:
		return 0


def area_or_perimeter(l, w):
	if l == w:
		return l * w
	else:
		x = l * 2
		y = w * 2
		z = x + y
		return z


def area_or_perimeter(l, w):
	area_rectangle = l * w
	area_square = l * l
	perimeter_rectangle = 2 * (l + w)
	perimeter_square = 4 * l
	if l == w:
		return area_square
	else:
		return perimeter_rectangle


def area_or_perimeter(I, W):
	if I != W:
		return 2 * I + 2 * W
	else:
		return I * W


def area_or_perimeter(l, w):
	if l == w:
		return l * w
	if l != w:
		x = 2 * l
		y = 2 * w
		return x + y


def area_or_perimeter(l, w):
	a = lambda l, w: l * w if l == w else 2 * l + 2 * w
	return a(l, w)


def area_or_perimeter(l, w):
	square = l == w
	if square == True:
		return l * w
	else:
		return 2 * (l + w)


def area_or_perimeter(l, w):
	import math
	return math.pow(l, 2) if l == w else int(2 * l + 2 * w)


import unittest

def area_or_perimeter(length, width):
	return length * width if length == width else 2 * length + 2 * width

class TestAreaOrPerimeter(unittest.TestCase):

	def test_area(self):
		self.assertEqual(area_or_perimeter(length=4, width=4), 16)

	def test_perimeter(self):
		self.assertEqual(area_or_perimeter(length=10, width=4), 28)


def area_or_perimeter(l, w):
	print(l, w)
	if l == w:
		return 0.5 * (l * 4 * (w / 2))
	else:
		return (l + w) * 2


def area_or_perimeter(l, w):
	if l == w:
		return l * w
	elif l < w or l > w:
		return l * 2 + w * 2


def area_or_perimeter(le, wi):
	if le == wi:
		return le * wi
	else:
		return 2 * le + 2 * wi


def area_or_perimeter(l, w):
	square = l * w
	if l == w:
		return square
	else:
		return l + l + w + w


def area_or_perimeter(l, w):
	rectangle_perimeter = 2 * (l + w)
	square_area = l * l
	if l == w:
		return square_area
	else:
		return rectangle_perimeter


def area_or_perimeter(l, w):
	if l == w:
		return l ** 2
	else:
		l2 = l * 2
		r2 = w * 2
		return l2 + r2


from math import *

def area_or_perimeter(l, w):
	if l == w:
		area = l * w
		return area
	else:
		p = l + w + l + w
		return p


def area_or_perimeter(l, w):
	s = l * w
	p = (l + w) * 2
	if l == w:
		return s
	else:
		return p


def area_or_perimeter(l, w):
	l = int(l)
	w = int(w)
	if l == w:
		return l * w
	else:
		return l + l + w + w


def area_or_perimeter(l, w):
	if l == w:
		a = l * w
		return a
	else:
		b = l + w
		p = 2 * b
		return p


def area_or_perimeter(l, w):
	area = l * w
	perimeter = 2 * (l + w)
	if l == w:
		return area
	else:
		return perimeter


def area_or_perimeter(l, w):
	return l == w and l ** 2 or 2 * (l + w)


def area_or_perimeter(l, w):
	if l == w:
		return l * w
	else:
		return l + w + l + w
l = 4
w = 4
print(l + w)


def area_or_perimeter(l, w):
	if l == w:
		return l * w
	else:
		c = l * 2
		b = w * 2
		return c + b


def area_or_perimeter(l, w):
	if l == w:
		answer = l * w
	elif l != w:
		answer = l + l + w + w
	return answer


def area_or_perimeter(l, w):
	length = l
	width = w
	if length == width:
		return length * width
	return (length + width) * 2


def area_or_perimeter(l, w):
	ans = 2 * l + 2 * w
	if l == w:
		ans = l * w
	return ans


def area_or_perimeter(l, w):
	if l == w:
		Square = l * w
		return Square
	else:
		Rectangle = (l + w) * 2
		return Rectangle