Discuss / Python / 我的代码

我的代码

Topic source

tycoonBrain

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

import math

def quadratic(a,b,c):

for i in [a,b,c]:

if not isinstance(i,(int,float)):

raise TypeError('bad operand type')

t = b*b-4*a*c

if t < 0:

print('该方程无解,请重新输入')

elif a==0:

x1,x2 = c/(-b)

else:

x1 = (-b-math.sqrt(t))/(2*a)

x2 = (-b+math.sqrt(t))/(2*a)

return x1,x2

a,b,c= eval(input('请输入依次三个数:\n'))

print('两个值分别为:\n',quadratic(a,b,c))


  • 1

Reply