Discuss / Python / 别问我为啥用print,爱好

别问我为啥用print,爱好

Topic source

vv阿甘vv

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

def quadratic(a, b, c):
    for x in (a, b, c):
        if not isinstance(x, (int, float)):
            raise TypeError("type error")
    y = b ** 2 - 4*a*c
    if y < 0:
        print("方程无实根!")
    elif y == 0:
        res = -b/2*a
        print("方程只有一个实根 %s" % str(res))
    else:
        res1 = (-b + math.sqrt(y))/2*a
        res2 = (-b - math.sqrt(y))/2*a
        print("方程有两个实根,分别是 %s, %s" % (str(res1), str(res2)))

废弄之神

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

你这个答案错的,代码应该改为:res = -b /2/a

废弄之神

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

你这个答案错的,代码应该改为:res = -b /2/a

我觉得,不止res那有问题,但我找不出来,毕竟我试了都运行不了


  • 1

Reply