python學習

import math
def  main():
    print ("this program find the real solution to a quadratic")
    a, b, c=eval(input("please input the coefficients(a,b,c):"))
    delta=b*b-4*a*c
    if delta>=0:
        delta=math.sqrt(delta)
        root1=(-b+delta)/(2*a)
        root2=(-b-delta)/(2*a)
        print ("\nThe solution are:", root1,root2)

main()

this program find the real solution to a quadratic
please input the coefficients(a,b,c):2,6,1

The solution are: -0.17712434446770464 -2.8228756555322954

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章