Discuss / Python / homework

homework

Topic source

逝去的9211

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

-- coding: utf-8 --

import math def quadratic(a): if not isinstance(a, (int,float)): raise TypeError('first bad perand type') if not isinstance(b, (int,float)): raise TypeError('second bad perand type') if not isinstance(c,(int,float)): raise TypeError('third bad perand type') temp=bb-4ac if temp<0: return '该方程没有实数解' elif a==0: return '该方程不是一元二次方程,是一元一次方程' elif temp==0: return '该方程只有一个解,解为:%f'%(-b/(2a)) else: return (-b+math.sqrt(temp))/(2a),(-b-math.sqrt(temp))/(2a)

在此插入代码

  • 1

Reply