lerrorgk 2017-08-25 01:52 采纳率: 25%
浏览 1405
已采纳

下面这个解二次方程的python程序中哪里出错

import math
def main():
        print("Let us finds the solutions to a quadratic\n")
        a, b, c = eval(input("Do enter the coefficients (a, b, c):"))
        delta = b * b - 4 * a * c
        if a == 0:
                x = -b / c
                print("\nThere is an solution",x)
        elif delta < 0:
                print("\nThe equation has no real roots!")
        elif delta == 0:
                x = -b / (2 * a)
                print("\nThere is a double root at",x)
        else:
                discRoot = math.sqrt(delta)
                x1 = (-b + discRoot) / (2 * a)
                x2 = (-b - discRoot) / (2 * a)
                print("\nThe solutions are:", x1, x2)

main()

错误代码
Do enter the coefficients (a, b, c):4 4 1
Traceback (most recent call last):
File "D:/c/mooc/04/01.quadratic4.py", line 20, in
main()
File "D:/c/mooc/04/01.quadratic4.py", line 4, in main
a, b, c = eval(input("Do enter the coefficients (a, b, c):"))
File "", line 1
4 4 1
^
SyntaxError: invalid syntax

  • 写回答

1条回答 默认 最新

  • ogelp 2017-08-25 02:01
    关注

    a b c 输入的时候要用逗号隔开,不是空格隔开。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?