import math # 定义一个函数,接受三个参数,返回一个一元二次方程的两个解 def quadratic(a,b,c): m=b*b-4*a*c if m>=0: x=(-b+math.sqrt(m))/(2*a) y=(-b-math.sqrt(m))/(2*a) return x,y else: return ‘no answer!‘ print(quadratic(2,3,1)) # 快速复制到下一行,CTR+D、 print(quadratic(1,3,1)) print(quadratic(1,4,4)) print(quadratic(1,-4,4))
原文地址:https://www.cnblogs.com/Jack1816274408/p/10703922.html
时间: 2024-10-12 20:07:52