Discuss / Python / 迷迷糊糊的

迷迷糊糊的

Topic source

丶丶光

#1 Created at ... [Delete] [Delete and Lock User]
  • -就这水平了,上学数学渣 ,百度和问学长后的结果 .... ``` 在此插入代码

```

-- coding: utf-8 --

import math

def quadratic(a, b, c):

if a!=0:        
    w = b*b-4*a*c
    if w < 0:
        return 'error'
    else:
        x1=(-b+math.sqrt(w))/(2*a)
        x2=(-b-math.sqrt(w))/(2*a)
    return'(%.1f,%.1f)'%(x1,x2)
else:
    pass

测试:

print(quadratic(2, 3, 1)) # => (-0.5, -1.0) print(quadratic(1, 3, -4)) # => (1.0, -4.0)

报三春晖

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

a可以等0啊。a=0时,x有一个解


  • 1

Reply