# -*- coding: utf-8 -*-import math def quadratic(a, b, c): if not (isinstance(a, (int, float)) and isinstance(b, (int, float)) and isinstance(c, (int, float))): raise TypeError('bad operand type') delta = b**2-4*a*c if delta < 0: print("no result!\n") elif delta == 0: x1 = b/(-2*a) print("x1=x2=%.3f\n" % x1) else: x1 = (b+math.sqrt(delta)) / 2*a x2 = (b-math.sqrt(delta)) / 2*a print("x1=%.3f\nx2=%.3f\n" % (x1, x2)) return
Sign in to make a reply
520bv