Discuss / Python / 供参考相互学习:

供参考相互学习:

Topic source

安行农园

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

-- coding: utf-8 --

import math

def quadratic(a,b,c):

t = b*b - 4*a*c

if t > 0:
   x1 = x2 = -b/2*a
   return x1,x2
elif t == 0:
   x1 = (-b + math.sqrt(t))/2*a
   x2 = (-b - math.sqrt(t))/2*a
   return x1,x2
else:
   return('此方程无解')

a = int(input('请输入a的值:')) b = int(input('请输入b的值:')) c = int(input('请输入c的值:')) print(quadratic(a,b,c))

思喵simiao

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

是我数学白学了还是你两种情况写反了?突然惶恐

怎么就无解了,复根也是解啊!!!!

安行农园

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

-- coding: utf-8 -- import math

def quadratic(a,b,c):

t = bb - 4a*c

if t == 0: x1 = x2 = -b/2a return x1,x2 elif t > 0: x1 = (-b + math.sqrt(t))/2a x2 = (-b - math.sqrt(t))/2*a return x1,x2 else: return('此方程无解') a = int(input('请输入a的值:')) b = int(input('请输入b的值:')) c = int(input('请输入c的值:')) print(quadratic(a,b,c))


  • 1

Reply