Discuss / Python / 交作业啦

交作业啦

Topic source

BillCode

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

import math

def quandratic(a,b,c): x = (b*2)-(4a*c)

if a == 0:
    return -(c/b),-(c/b)
elif x >= 0:
    x1 = (-(b)+math.sqrt(x))/(2*a)
    x2 = (-(b)-math.sqrt(x))/(2*a)

    return x1,x2
else:
    return '该方程无解'

print(quandratic(2,3,1)) print(quandratic(1, 3, -4))

BillCode

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

def quandratic(a,b,c):

x = (b**2)-(4*a*c)

if a == 0:
    return -(c/b)
elif x >= 0:
    x1 = (-(b)+math.sqrt(x))/(2*a)
    x2 = (-(b)-math.sqrt(x))/(2*a)

    return x1,x2
else:
    return '该方程无解'

  • 1

Reply