在我的python程序中苦苦挣扎

时间:2014-05-03 07:09:35

标签: python equation quadratic

所以我在python中编写这个程序进行练习:

from math import sqrt
Antwoord = 0

while Antwoord != "yes": 
    print "In many cases of Maths there will be a quadratic equation"
    print "The question is how do you solve it? Through this amazing program"
    print
    print "These equations comes in a form : ax2 + bx + c"
    print "Now lets solve yours!"

    eq_a = raw_input("What is your a value?")       #Asking values
    eq_b = raw_input("What is your b value?")
    eq_c = raw_input("What is your c value?")

    vierkantsw = (eq_b) ** 2 - 4(eq_a)(eq_c)
    teller1 = -(eq_b) + sqrt(vierkantsw)     # -b+sqrt((b)**2 -4(a)(c))
    teller2 = -(eq_b) - sqrt(vierkantsw)     # -b-sqrt((b)**2 -4(a)(c))
    noemer = 2 * eq_a                        # 2(a)

    if vierkantsw < 0 :
        print "Your equation gives no solution : insolubale"     # Vir nie-reele getal 
    else:
        total1 = float(teller1) / noemer                    # Bereken die twee oplos
        total2 = float(teller2 / noemer 
        print "The two solutions are : " + total1 + " and " + total2  
    Antwoord = raw_input("Are you finished?")                   #Vra vir looping 

所以这个程序应该计算一个二次方程并循环它以获得更多控制,我在终端中运行程序以及编辑器的“运行”函数,两者都给了我相同的语法错误?

    print "The two solutions are : " + total1 + " and " + total2  
        ^
SyntaxError: invalid syntax

有人可以帮助我吗?

提前谢谢!

1 个答案:

答案 0 :(得分:4)

你在上一行的“teller2”之后错过了一个结束括号(即“)”。