# -*- coding: utf-8 -*- import math def quadratic(a, b, c): delta=b**2-4*a*c if (delta < 0): return("无解") elif (delta > 0): x1 = (-b+math.sqrt(b*b-4*a*c))/(2*a) x2 = (-b-math.sqrt(b*b-4*a*c))/(2*a) return(x1,x2) # 测试: print(quadratic(2, 3, 1)) # => (-0.5, -1.0) print(quadratic(1, 3, -4)) # => (1.0, -4.0)
Sign in to make a reply
磁暴王者特斯拉