日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Python程序:計(jì)算二次方程根

創(chuàng)新互聯(lián)python教程:

寫一個(gè) Python 程序,用一個(gè)例子找到一個(gè)二次方程的根。二次方程的數(shù)學(xué)表示是 ax +bx+c = 0。一個(gè)二次方程可以有兩個(gè)根,它們完全取決于判別式。如果判別式> 0,則該方程存在兩個(gè)不同的實(shí)根

如果判別式= 0,則存在兩個(gè)相等的實(shí)根。

而如果判別< 0, Two Distinct Complex Roots exists.

用 elif 求二次方程根的 Python 程序

這個(gè) python 程序允許用戶輸入 a、b 和 c 的三個(gè)值。通過(guò)使用這些值,這個(gè) Python 代碼使用 Elif 語(yǔ)句找到一個(gè)二次方程的根。

# Python Program to find roots of a Quadratic Equation
import math

a = int(input("Please Enter a Value of a Quadratic Equation : "))
b = int(input("Please Enter b Value of a Quadratic Equation : "))
c = int(input("Please Enter c Value of a Quadratic Equation : "))

discriminant = (b * b) - (4 * a * c)

if(discriminant > 0):
    root1 = (-b + math.sqrt(discriminant) / (2 * a))
    root2 = (-b - math.sqrt(discriminant) / (2 * a))
    print("Two Distinct Real Roots Exists: root1 = %.2f and root2 = %.2f" %(root1, root2))
elif(discriminant == 0):
    root1 = root2 = -b / (2 * a)
    print("Two Equal and Real Roots Exists: root1 = %.2f and root2 = %.2f" %(root1, root2))
elif(discriminant < 0):
    root1 = root2 = -b / (2 * a)
    imaginary = math.sqrt(-discriminant) / (2 * a)
    print("Two Distinct Complex Roots Exists: root1 = %.2f+%.2f and root2 = %.2f-%.2f" %(root1, imaginary, root2, imaginary))


分享標(biāo)題:Python程序:計(jì)算二次方程根
鏈接地址:http://www.dlmjj.cn/article/dpcjpjg.html