Discuss / Python / 作业

作业

Topic source

FJ-W97

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

import math def quadratic(a , b, c): if not isinstance(a,(int,float)): raise TypeError("TypeError in a") if not isinstance(b,(int,float)): raise TypeError("TypeError in b") if not isinstance(c,(int,float)): raise TypeError("TypeError in c") part = bb-4ac if part>0: x1 = (-b+math.sqrt(part))/(2a) x2 = (-b-math.sqrt(part))/(2a) return x1,x2 elif part==0: x1 = -b/(2a) x2 = x1 return x1,x2 else: return'无解' print(quadratic(1,3,-4))


  • 1

Reply