Implement a method that accepts 3 integer values a, b, c. The method should return true if a triangle can be built with the sides of given length and false in any other case.

(In this case, all triangles must have surface greater than 0 to be accepted).

Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code:
def is_triangle(a, b, c):
	

Solutions:
def is_triangle(a, b, c):
	return a < b + c and b < a + c and (c < a + b)


def is_triangle(a, b, c):
	(a, b, c) = sorted([a, b, c])
	return a + b > c


def is_triangle(a, b, c):
	if a <= 0 | b <= 0 | c <= 0:
		return False
	elif a + b <= c or a + c <= b or b + c <= a:
		return False
	else:
		return True


def is_triangle(a, b, c):
	return abs(a - b) < c < a + b


def is_triangle(a, b, c):
	s = [a, b, c]
	for i in s:
		if sum(s) - i <= i:
			return False
	return True


def is_triangle(a, b, c):
	return 2 * max(a, b, c) < a + b + c


def is_triangle(a, b, c):
	if a + b <= c or a + c <= b or b + c <= a:
		return False
	else:
		return True


def is_triangle(a, b, c):
	return all([a + b > c, a + c > b, b + c > a])


def is_triangle(a, b, c):
	if a + b + c == 0:
		return False
	if a + b <= c:
		return False
	if a + c <= b:
		return False
	if b + c <= a:
		return False
	return True


def is_triangle(a, b, c):
	if a <= 0 or b <= 0 or c <= 0:
		return False
	sum = a + b + c
	if fits(sum, max(a, b, c)):
		return True
	return False

def fits(sum, a):
	return sum - a > a


is_triangle = lambda _, a, b: sum(sorted([_, a, b])[:2]) > sorted([_, a, b])[2]


def is_triangle(a, b, c):
	sides = [a, b, c]
	max_side = max(sides)
	if sum(sides) - max_side > max_side:
		return True
	else:
		return False


def is_triangle(a, b, c):
	s = a + b + c
	if s - max(a, b, c) > max(a, b, c):
		return True
	return False


def is_triangle(a, b, c):
	cond1 = a + b > c
	cond2 = b + c > a
	cond3 = a + c > b
	list = [cond1, cond2, cond3]
	if False in list:
		return False
	return True


def is_triangle(x, y, z):
	return x < y + z and y < x + z and (z < x + y)


def is_triangle(a, b, c):
	t1 = a + b > c
	t2 = a + c > b
	t3 = b + c > a
	return t1 and t2 and t3


def is_triangle(*sides):
	return sum(sorted(sides)[:2]) > max(sides)


def is_triangle(a, b, c):
	max_number = max([a, b, c])
	if sum([a, b, c]) - max_number > max_number:
		return True
	return False


def is_triangle(a, b, c):
	if a > 0 and b > 0 and (c > 0):
		if a + b > c and a + c > b and (c + b > a):
			return True
		else:
			return False
	return False


def is_triangle(a, b, c):
	llist = [a, b, c]
	llist.sort()
	highest = llist[2]
	sumrest = llist[0] + llist[1]
	if highest < sumrest:
		return True
	return False


def is_triangle(a, b, c):
	if a + b > c and a + c > b and (b + c > a):
		return True
	return False


def is_triangle(a, b, c):
	lst = [int(a), int(b), int(c)]
	lst = sorted(lst)
	if lst[0] + lst[1] > lst[2]:
		return True
	else:
		return False


def is_triangle(a, b, c):
	lengths = [a, b, c]
	x = sorted(lengths)
	print((x, x[0] + x[1]))
	if x[0] + x[1] > x[2]:
		return True
	else:
		return False


def is_triangle(a, b, c):
	max_int = max(a, b, c)
	min_int = min(a, b, c)
	if max_int == a:
		sum = b + c
		if sum > a:
			return True
	if max_int == b:
		sum = a + c
		if sum > b:
			return True
	if max_int == c:
		sum = a + b
		if sum > c:
			return True
	return False


def is_triangle(a, b, c):
	if a == None or b == None or c == None:
		return False
	l_tri = sorted([a, b, c])
	if l_tri[2] >= l_tri[0] + l_tri[1]:
		return False
	return True


def is_triangle(a, b, c):
	tab_coter = [a, b, c]
	tab_coter.sort()
	calc_long_coter = tab_coter[0] + tab_coter[1]
	if tab_coter[2] < calc_long_coter:
		return True
	return False


def is_triangle(a, b, c):
	s = sorted([a, b, c])
	return False if s[0] < 1 or sum(s[:-1]) <= s[2] else True


def is_triangle(a, b, c):
	lts = [a, b, c]
	lts.sort()
	return lts[2] < lts[1] + lts[0]


def is_triangle(a, b, c):
	triangleList = [a, b, c]
	triangleList.sort()
	if triangleList[0] + triangleList[1] > triangleList[2]:
		return True
	else:
		return False


def is_triangle(a, b, c):
	out = []
	out.append(a)
	out.append(b)
	out.append(c)
	out.sort()
	if out[2] >= out[0] + out[1]:
		return False
	else:
		return True


def is_triangle(a, b, c):
	if not a + b > c or not a + c > b or (not b + c > a):
		print(('AB pair', a + b, c))
		print(('AC pair', a + c, b))
		print(('BC pair', b + c, a))
		return False
	else:
		return True


def is_triangle(a, b, c):
	if 2 * max([a, b, c]) < a + b + c:
		return True
	else:
		return False


def is_triangle(a, b, c):
	return a + b > c and b + c > a and (c + a > b) and (a > 0) and (b > 0) and (c > 0)
	return False


def is_triangle(a, b, c):
	listOfSides = [a, b, c]
	if max(listOfSides) >= sum(listOfSides) - max(listOfSides):
		return False
	return True


def is_triangle(a, b, c):
	sum = a + b + c
	for side in (a, b, c):
		if sum - side <= side:
			return False
	return True


def is_triangle(a, b, c):
	x = max(a, b, c)
	for i in (a, b, c):
		if x == i and x < a + b + c - i:
			return True
	return False


def is_triangle(a, b, c):
	if a + b > c and abs(a - b) < c:
		return True
	elif a + c > b and abs(a - c) < b:
		return True
	elif b + c > a and abs(b - c) < a:
		return True
	else:
		return False


def is_triangle(a, b, c):
	if a > 0 and b > 0 and (c > 0):
		reference = sorted([a, b, c])
		if reference[2] < reference[0] + reference[1]:
			return True
		else:
			return False
	else:
		return False


def is_triangle(a, b, c):
	if a + b > c and a + c > b and (b + c > a):
		print('You can make a triangle with these numbers')
		return True
	else:
		print('You cannot make a triangle with these numbers')
		return False


def is_triangle(a, b, c):
	if any((side <= 0 for side in (a, b, c))):
		return False
	sides = sorted([a, b, c])
	if sides[0] + sides[1] <= sides[2]:
		return False
	return True


def is_triangle(a, b, c):
	v = [a, b, c]
	m = max(v)
	v.remove(m)
	return m < sum(v)


def is_triangle(a, b, c):
	my_flag = False
	if a + b > c and c + b > a and (a + c > b):
		my_flag = True
	else:
		my_flag = False
	return my_flag


def is_triangle(a, b, c):
	result = ''
	if a + b <= c:
		result = False
	elif a + c <= b:
		result = False
	elif b + c <= a:
		result = False
	else:
		result = True
	return result


import math

def is_triangle(a, b, c):
	sides = (a, b, c)
	if sorted(sides)[-1] >= sorted(sides)[0] + sorted(sides)[1]:
		return False
	return True


def is_triangle(a, b, c):
	table = [a, b, c]
	table.sort()
	return table[0] + table[1] > table[2]


def is_triangle(a, b, c):
	if sum([a, b]) > c and sum([b, c]) > a and (sum([a, c]) > b):
		return True
	else:
		return False


def is_triangle(a, b, c):
	if a == 0 or b == 0 or c == 0:
		return 0
	if a + b <= c or b + c <= a or a + c <= b:
		return 0
	else:
		return 1


def is_triangle(a, b, c):
	list_ = [a, b, c]
	if sorted(list_)[0] + sorted(list_)[1] > sorted(list_)[2]:
		if sorted(list_)[0] > 0 and sorted(list_)[1] > 0 and (sorted(list_)[2] > 0):
			return True
	return False


def is_triangle(a, b, c):
	x = a + b
	y = b + c
	z = a + c
	if x > c and y > a and (z > b):
		return True
	else:
		return False


def is_triangle(a, b, c):
	if (a or b or c) < 0:
		return False
	v = list()
	v.append(a)
	v.append(b)
	v.append(c)
	v.sort()
	_a = v.pop()
	_b = v.pop()
	_c = v.pop()
	if _a < _b + _c:
		return True
	if _a == _b + _c:
		return False
	return False


def is_triangle(a, b, c):
	if a + b > c and b + c > a and (a + c > b):
		result = True
		print(result)
	else:
		result = False
		print(result)
	return result


def is_triangle(a, b, c):
	x = max(a, b, c)
	lista = [a, b, c]
	lista.remove(x)
	if x < sum(lista):
		return True
	else:
		return False


def is_triangle(a, b, c):
	k = [a + b > c, a + c > b, b + c > a]
	return not False in k


def is_triangle(a, b, c):
	sides = [a, b, c]
	a = max(sides)
	sides.remove(a)
	if sum(sides) > a:
		return True
	return False


def is_triangle(a, b, c):
	result = False
	if a + b > c:
		if a + c > b:
			if c + b > a:
				result = True
	return result


def is_triangle(a, b, c):
	biggest_arg = max([a, b, c])
	return True if biggest_arg < sum([a, b, c]) - biggest_arg else False


def is_triangle(a, b, c):
	mylist = [a, b, c]
	mylist = sorted(mylist)
	if mylist[0] < mylist[1] + mylist[2]:
		if mylist[1] < mylist[0] + mylist[2]:
			if mylist[2] < mylist[0] + mylist[1]:
				return True
	return False


def is_triangle(a, b, c):
	sides = (a, b, c)
	sides = sorted(sides)
	c = sides[-1]
	b = sides[1]
	a = sides[0]
	return c < a + b


def is_triangle(a, b, c):
	a = sorted([a, b, c])
	return a[2] < a[0] + a[1]