#chp14.常用數學函數庫 #範例14-2:使用math數學模組函數庫 #https://www.w3schools.com/python/python_math.asp #觀念:python內定提供的數學模組有2種 #(1)基本數學函數:abs(), max(), pow(), round() #(2)math模組數學函數:sqrt(), floor(), ceil() #注意:使用math模組,要先import: import math #import math #1.----- 開根號 math.sqrt() --------- #a1 = 25 #print(a1, "的開根號=") #2.----- 無條件捨去 math.floor()------ #a2 = 5.6 #print(a2, "的無條件捨去=") #2.----- 四捨五入 math.round()------ #a2 = 5.6 #print(a2, "的無條件進位=") #2.----- 四捨五入 math.round()------ #a2 = 5.6 #print(a2, "的四捨五入=") #四捨五入round()屬於基本數學函數,不是math模組數學函數 #3.----- pi math.pi() --------- #a3 = 2 #print("半徑=", a3, "的圓周長=") #------------------------------------------------------- #------------------------------------------------------- #範例14-2:使用math數學模組函數庫 #https://www.w3schools.com/python/python_math.asp #觀念:python內定提供的數學模組有2種 #(1)基本數學函數:abs(), max(), pow(), round() #(2)math模組數學函數:sqrt(), floor(), ceil() #注意:使用math模組,要先import: import math import math #1.----- 開根號 math.sqrt() --------- a1 = 25 print(a1, "的開根號=", math.sqrt(a1)) #2.----- 無條件捨去 math.floor()------ a2 = 5.6 print(a2, "的無條件捨去=", math.floor(a2)) #2.----- 四捨五入 math.round()------ a2 = 5.6 print(a2, "的無條件進位=", math.ceil(a2)) #2.----- 四捨五入 math.round()------ a2 = 5.6 print(a2, "的四捨五入=", round(a2)) #四捨五入round()屬於基本數學函數,不是math模組數學函數 #3.----- pi math.pi() --------- a3 = 2 print("半徑=", a3, "的圓周長=", 2 * math.pi * a3) #-------------------------------------------------------