Discuss / Python / 作业

作业

Topic source

JasF

#1 Created at ... [Delete] [Delete and Lock User]

-- coding: utf-8 --

import math

def quadratic(a, b, c): if not isinstance(a,(int,float)): raise TypeError('bad operand type a') if not isinstance(b,(int,float)): raise TypeError('bad operand type b') if not isinstance(c,(int,float)): raise TypeError('bad operand type c') sign = (bb)-(4ac) if sign >= 0: x = (-b + math.sqrt(sign)) / (2 a) y = (-b - math.sqrt(sign)) / (2 * a) else: print('Error,this quadratic no result') return x,y print(quadratic(2, 3, 1)) # => (-0.5, -1.0) print(quadratic(1, 3, -4)) # => (1.0, -4.0)


  • 1

Reply