我正在制作一个二次形式计算器,接受a,b和c,其中an不等于0

时间:2016-12-03 20:07:31

标签: python python-2.7 formula quadratic

这不完整,我知道如果an不等于零,我必须使用if / else语句来返回错误,但是现在我只是想让我的公式工作。我应该定义判别式和二次方程式。当我有以下代码时:

def descriminant(a, b, c): #Setting input perameters for descriminant

    disc = (b**2-4*a*c) #Defining what descriminant does with disc
    return disc #returns and allows to be used again instead of print which doesnt allow you to use it again

def quad_form(a, b, c): #Defining quad form w/ input a, b, c

    quad_form1=(-1*b + float((descriminant**.5 (a, b, c))/2*a)) #Defining + forumula for quad form
    quad_form2=(-1*b - float((descriminant**.5 (a, b, c))/2*a)) #Defining - forumula for quad form

    return quad_form1
    return quad_form2

UI=input("Enter the coefficients of a quadratic where A is not equal to zero: ")
QF1=quad_form1(UI)
QF2=quad_form2(UI)
print QF1, QF2

错误

名称quad_form1未定义

并且对于quad_form2

也是如此

有什么想法吗?

0 个答案:

没有答案