想增加一個判斷 可是不知道為什么錯誤了
>>> z='b*b-4ac'
>>> import math
>>> def qijie(a,b,c):
...? ? ?t=math.sqrt(z)
...? ? ?if z>=0:
...? ? ? ? ?return(-b+t)/(2*a),(-b-t)/(2*a)
...? ? ?else:
...? ? ? ? ?print(error)
...
>>> print((qijie(1,5,9)))
Traceback (most recent call last):
? File "<stdin>", line 1, in <module>
? File "<stdin>", line 2, in qijie
TypeError: must be real number, not str
2019-03-18
...
z=b*b-4*a*c就行了,你加了引號把他變成了字符串,字符串咋開根號啊,所以錯誤說不能是str
2019-03-17
你的判斷語句 應該在 給t 賦值之前 不然 給t開根號的時候 就已經數學錯誤了
2019-03-17
4ac應該是4*a*c