Discuss / Python / zuoye

zuoye

Topic source

-- coding: utf-8 --

import math def quadratic(a,b,c): if not isinstance(a, (int, float) and b, (int, float) and c, (int, float)): raise TypeError('bad operand type') s = bb - 4ac if a == 0: x = -c/b return x elif s < 0: return 'Error' elif s > 0: x1 = (-b+math.sqrt(bb- 4ac))/2a x2 = (-b-math.sqrt(bb- 4ac))/2a return (x1,x2) elif s == 0: x = -b/(2a) return x

老师,我为何调用不出来这个函数呢 from math import quadratic调不出来的 我保存之后备注是math.py

-- coding: utf-8 --

import math def quadratic(a,b,c): if not isinstance(a, (int, float)) and (b, (int, float)) and (c, (int, float)): raise TypeError('bad operand type') s = bb - 4ac if a == 0: x = -c/b return x elif s < 0: return 'Error' elif s > 0: x1 = -(b+math.sqrt(bb- 4ac))/(2a) x2 = -(b-math.sqrt(bb- 4ac))/(2a) return (x1,x2) elif s == 0: x = -b/(2a) return x print(quadratic(2, 3, 1)) print(quadratic(1, 3, -4))

现在搞对了,原来是有些逻辑存在错误,还是自己太马虎了


  • 1

Reply