Discuss / Python / 作业

作业

Topic source

import math a = float(input("请输入a的值")) b = float(input("请输入b的值")) c = float(input("请输入c的值")) def quadratic(a,b,c): for check in (a,b,c): if not isinstance(check(int,float)): raise TypeError("bad operand type") z = b b - 4 a c if z == 0: return("无解") elif z > 0: x1 = (-b + math.sqrt(z)) / (2 a) x2 = (-b - math.sqrt(z)) / (2 * a) return(x1,x2) else: return("无解")

print(quadratic(a,b,c))


  • 1

Reply