Discuss / Python / 我的答案,供参考

我的答案,供参考

Topic source

import math

def quadratic():

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

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

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

    sol_judge = b**2-4*a*c

    if sol_judge >= 0:

        x1 = (-b + math.sqrt(sol_judge))/2*a

        x2 = (-b - math.sqrt(sol_judge))/2*a

        return x1, x2

    else:

        print('No real solution')

x1, x2 = quadratic()

print('solutions:{},{}'.format(x1,x2))


  • 1

Reply