Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

คำนวณ Wind Chill Factor (WCF) หรือ Wind Chill Index (WCI) ใน Python

Wind Chill Factor เป็นตัวบ่งชี้ว่าเรารู้สึกเย็นแค่ไหน ไม่ใช่เพราะอุณหภูมิบรรยากาศอย่างเดียว แต่คำนึงถึงความเร็วลมด้วย มันรวมทั้งสองปัจจัยในรูปสมการและให้การวัดว่าเย็นแค่ไหนจริงๆ เมื่อลมพัดเร็ว แม้อุณหภูมิจะไม่เปลี่ยนแปลง

ด้านล่างคือสมการสำหรับคำนวณ Wind Chill Factor:

Twc = 13.12 + 0.6215 Ta - 11.37 v0.16 + 0.3965 Ta v0.16

โดย Twc คือ wind chill index ตามมาตรฐานอุณหภูมิเซลเซียส
Ta คือ อุณหภูมิอากาศในองศาเซลเซียส
v คือ ความเร็วลมที่ความสูง 10 เมตร (33 ฟุต) มาตรฐาน anemometer ในกิโลเมตรต่อชั่วโมง

เพื่อใช้สูตรนี้คำนวณค่า Wind Chill Factor เราจะใช้ไลบรารี math ของ Python เนื่องจากฟังก์ชันยกกำลัง (power function) มีอยู่ในไลบรารีนี้ โปรแกรมด้านล่างทำให้บรรลุเป้าหมายนี้

ตัวอย่าง

import math

wind = float(input("Enter wind speed in kilometers/hour: "))
temperature = float(input("Enter air temperature in degrees Celsius: "))

wind_chill_factor_index = 13.12 + 0.6215 * temperature \
    - 11.37 * math.pow(wind, 0.16) \
    + 0.3965 * temperature * math.pow(wind, 0.16)

print("The wind chill index is", int(round(wind_chill_factor_index, 0)))

ผลลัพธ์

การรันโค้ดข้างต้นจะได้ผลลัพธ์ดังนี้:

Enter wind speed in kilometers/hour: 16
Enter air temperature in degrees Celsius: 27
The wind chill index is 29