SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
.selections
Exercise:
Programming Excercises
Question:20 | ISBN:978013274719 | Edition: 6

Question

(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.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

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

0 0

Discussions

Post the discussion to improve the above solution.