这个题咋解
应该怎么做 这个 我会啊 a3982030 发表于 2019-12-1 16:42这个 我会啊
哥哥咋做啊,能看看吗 不是有求根公式吗? 无解:a=b=0 || c!=0
无穷解:a=b=c=0
一次方程解:a=0 && b!=0
二次方程实数解:a!=0 & b*b-4*a*c>=0
二次方程复数解:a!=0 && b*b-4*a*c<0 hzqmwne 发表于 2019-12-1 17:13
无解:a=b=0 || c!=0
无穷解:a=b=c=0
一次方程解:a=0 && b!=0
理解了,多谢多谢 哈哈,太难了吧,我也不会呢{:1_909:} hzqmwne 发表于 2019-12-1 17:13
无解:a=b=0 || c!=0
无穷解:a=b=c=0
一次方程解:a=0 && b!=0
厉害👍厉害 python
import math
def quadratic(a, b, c):
if not isinstance(a, int) or not isinstance(b, int) or not isinstance(c, int):
raise TypeError('bad operand type')
if a == 0:
if b == 0:
if c == 0 :
result = ['无穷解']
else:
result = ['无解']
else:
#x1 = -c/b
x1 = '%d/%d' % (-c, b)
result = ['单实数解', x1]
elif b == 0 and c == 0:
result = ['单实数解', '0']
elif b**2-4*a*c > 0:
#x1 = (-b+math.sqrt(b**2-4*a*c))/2/a
#x2 = (-b-math.sqrt(b**2-4*a*c))/2/a
x1 = '(%d+sqrt(%d))/%d' % (-b, b**2-4*a*c, 2*a)
x2 = '(%d-sqrt(%d))/%d' % (-b, b**2-4*a*c, 2*a)
result = ['双实数解', x1, x2]
elif b**2-4*a*c == 0:
#x1 = -b/2/a
x1 = '%d/%d' % (-b, 2*a)
result = ['单实数解', x1]
else:
#x0 = math.sqrt(4*a*c-b**2)
#x1 = '(%d+%fi)/%d' % (-b, x0, 2*a)
#x2 = '(%d-%fi)/%d' % (-b, x0, 2*a)
x1 = '(%d+sqrt(%d)i)/%d' % (-b, 4*a*c-b**2, 2*a)
x2 = '(%d-sqrt(%d)i)/%d' % (-b, 4*a*c-b**2, 2*a)
result = ['双虚数解', x1, x2]
return result
a = int(input('输入整数a: '))
b = int(input('输入整数b: '))
c = int(input('输入整数c: '))
print('-----')
r = quadratic(a, b, c)
if len(r) == 1:
print(r)
elif len(r) == 2:
print('%s\nx = %s' % (r, r))
else:
print('%s\nx1 = %s\nx2 = %s' % (r, r, r)) 楼上大神啊~~{:1_921:}
页:
[1]