Discuss / Python / 学习

学习

Topic source

友仔

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

import math

def quadratic(a, b, c):

    if not isinstance(a+b+c, (int, float)):

        raise TypeError('bad operand type')

    if b**2-4*a*c >= 0:

        x1 = (-b-math.sqrt(b**2-4*a*c))/(2*a)

        x2 = (-b+math.sqrt(b**2-4*a*c))/(2*a)

        print(x1, x2)

    else:

        print("don't have real root")

a = float(input('enter a:'))

b = float(input('enter b:'))

c = float(input('enter c:'))

quadratic(a, b, c)


  • 1

Reply