(Science: wind-chill temperature) Exercise 2.9 gives a formula to compute the wind-chill temperature. The formula is valid for temperatures in the range between -58°F and 41°F and for wind speed greater than or equal to 2. Write a program that prompts the user to enter a temperature and a wind speed. The program displays the wind-chill temperature if the input is valid; otherwise, it displays a message indicating whether the temperature and/or wind speed is invalid.
import math
#Prompt the user to enter a temperature and a wind speed
print("Enter the temperature in Fahrenheit between -58F and 41F: ")
temperature = float(input())
print("Enter the wind speed (>= 2) in miles per hour: ");
speed = float(input())
if (temperature <= -58 or temperature >= 41 or speed < 2):
print("The ",end="")
if (temperature <= -58 or temperature >= 41):
print("temperature ",end="")
if((temperature <= -58 or temperature >= 41) and speed < 2):
print("and ",end="")
if (speed < 2):
print("wind speed is invalid ")
#Compute the wind chill index
if((temperature>=-58 and temperature<=41)and speed>=2):
windChill = 35.74 + 0.6215 * temperature -35.75 * math.pow(speed, 0.16) +0.4275 *temperature * math.pow(speed, 0.16)
#Display Results
print("The wind chill index is {:.2f}".format(windChill))
Output:
Enter the temperature in Fahrenheit between -58F and 41F:
36
Enter the wind speed (>= 2) in miles per hour:
2
The wind chill index is 35.37