Implement function which will return sum of roots of a quadratic equation rounded to 2 decimal places, if there are any possible roots, else return **None/null/nil/nothing**. If you use discriminant,when discriminant = 0, x1 = x2 = root => return sum of both roots. There will always be valid arguments. 

Quadratic equation - https://en.wikipedia.org/wiki/Quadratic_equation

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

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

Solutions:
def roots(a, b, c):
	if b ** 2 >= 4 * a * c:
		return round(-b / a, 2)


def roots(a, b, c):
	import math
	d = b ** 2 - 4 * a * c
	if d > 0:
		return round(-2 * b / (2 * a), 2)
	elif d == 0:
		x = -b / (2 * a)
		return x * 2
	else:
		return None


def roots(a, b, c):
	return round(-b / a, 2) if b * b - 4 * a * c >= 0 else None


def roots(a, b, c):
	d = b ** 2 - 4 * a * c
	if d < 0:
		return None
	elif d == 0:
		return (-b + d ** 0.5) / (2 * a) * 2
	else:
		x1 = (-b + d ** 0.5) / (2 * a)
		x2 = (-b - d ** 0.5) / (2 * a)
		return round(x1 + x2, 2)


def roots(a, b, c):
	d = b ** 2 - 4 * a * c
	if d >= 0:
		return round(-b / a, 2)


roots = lambda a, b, c: None if b * b < a * c * 4 else round(-b / a, 2)


def roots(a, b, c):
	D = b ** 2 - 4 * a * c
	if D < 0:
		return None
	if D == 0:
		x = (-b + D ** 0.5) / (2 * a)
		return round(x * 2, 2)
	if D > 0:
		x1 = (-b + D ** 0.5) / (2 * a)
		x2 = (-b - D ** 0.5) / (2 * a)
		return round(x1 + x2, 2)


import math

def roots(a, b, c):
	dis = b ** 2 - 4 * a * c
	if dis < 0:
		return None
	return round((-b + math.sqrt(dis)) / (2 * a) + (-b - math.sqrt(dis)) / (2 * a), 2)


import math

def roots(a, b, c):
	d = round(b * b - 4 * a * c, 2)
	if d < 0:
		return None
	return round(-b / a, 2)