与python程序斗争

2024-05-23 17:27:12 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我写这个程序是为了用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 

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

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

有人能帮帮我吗?你知道吗

提前谢谢!你知道吗


Tags: the程序inputyourrawisvaluesqrt