Discuss / Python / 交7

落汐21

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

import math import numpy

def asd(a, b, c): l=4ac if numpy.square(b)<l : return '无实根' elif numpy.square(b)==l : x=-b/(2a) return x else : x1=(-b+math.sqrt(numpy.square(b)-l))/(2a) x2=(-b-math.sqrt(numpy.square(b)-l))/(2*a) return x1,x2

X=asd(2,3,1) Y=asd(1,3,-4) print(X,Y)

if X!=(-0.5, -1.0): print('测试失败') else: print('测试成功') if Y!= (1.0, -4.0): print('测试失败') else : print('测试成功')


  • 1

Reply