2016年9月17日 星期六

程式集訓 M90H063: 二次函數之極小值


#coding=utf8

#程式集訓 M90H063: 二次函數之極小值
'''
    M90H063: 二次函數之極小值
// 一元二次方程式: f(x) = a*x^2 + b*x + c
// 當 x = -b/2*a 時有最小值

'''
while True:
      try:
        a,b,c=(input("請輸入 AX^2+BX+C=0 的 A B C ?" ).split())
        a=float(a)
        b=float(b)
        c=float(c)
        break
              
      except ValueError:
         print ('這是不合法的輸入.  請再輸入一次...')
         continue

x = -b/(2*a)
print("當 x=",'{:6.2f}'.format(x),end="")
min1= (a*(x**2)) + b*x + c
print(" 有極小值為",'{:6.2f}'.format(min1))
#=========================================

     

================= RESTART: D:/程式語言 Python 入門/程式集訓/M90H063.py =================
請輸入 AX^2+BX+C=0 的 A B C ?12 3 2
當 x=  -0.12有極小值為   1.81
>>>

沒有留言:

張貼留言

多狀態開關 in EasyBuilderPro HMI 控制 Wokwi 的 RGB LED

多狀態開關  in EasyBuilderPro HMI 控制 Wokwi 的 RGB LED 若要建立顏色框,請下載檔案:   Kotak_warna ,然後解壓縮該檔案。這將開啟一個名為 color_box 的資料夾,其中包含 10 張圖片 IOT Address0 , Ad...