定义函数返回 ax2 + bx + c = 0 的两个解

# -*- coding: utf-8 -*-

import math

def quadratic(a, b, c):
   s = b*b - 4*a*c
   if a == 0:
       x = -c / b
       return x
   elif s==0:
         x = -b / 2*a
         return x
   elif s < 0:
       return 'no anwser'
   else:
         x = (-b + math.sqrt(s)) / (2 * a)
         y = (-b - math.sqrt(s)) / (2 * a)
         return x, y
posted @ 2017-03-05 02:48  fanren224  阅读(146)  评论(0编辑  收藏  举报