Discuss / Python / 交作业

交作业

Topic source

付伟根

#1 Created at ... [Delete] [Delete and Lock User]
# -*- coding: utf-8 -*-

import math

def quadratic(a,b,c):
    pos = b**2 - 4*a*c
    if pos < 0:
        return('该方程无解')
    elif pos == 0:
        x1 = -b/(2*a)
        return('该方程有相同的解:%s' % x1)
    else:
        x1 = (-b+math.sqrt(b**2-4*a*c))
        x2 = (-b-math.sqrt(b**2-4*a*c))
        return('该方程有不同的两个解:x1=%s, x2=%s' %(x1,x2))

a = float(input('a:'))
b = float(input('b:'))
c = float(input('c:'))



print(quadratic(a,float(b),float(c)))

  • 1

Reply