Wind chill is computed using the following formula:
Twc = 35.74 + 0.6215T - 35.75V0.16 + 0.4275TV0.16where T is the temperature and V the wind velocity. This formula is only valid for Fahrenheit temperatures in the range of -58 to 41 and wind speeds of at least 2 mph. You should validate the user supplied values to ensure they are in the correct range; print an error message and terminate otherwise.
For the Celsius results, simply convert your Fahrenheit values to Celsius and your wind speed in miles per hour to kilometers per hour. The formula to convert Fahrenheit to Celsius is:
C = (F - 32) * 5/9To convert miles to kilometers, multiply by 1.60934. Print floating point numbers with three digits after the decimal point. I printed each in a field of 9 spaces.
Notice that the degrees Fahrenheit or Celsius are labeled with a degree symbol (small raised circle). The degree symbol can be produced by including unicode into your string; the unicode for the degree symbol is "\u00B0". You can label a Fahrenheit value by printing the string " \u00B0" + "F". For Celsius, replace the "F" by "C".
Below are some examples of how running the program should look:
> python WindChill.py Enter Fahrenheit temperature: 100 Temperature should be in range [-58 .. 41]. > python WindChill.py Enter Fahrenheit temperature: -60 Temperature should be in range [-58 .. 41]. > python WindChill.py Enter Fahrenheit temperature: 32.0 Enter wind speed in miles per hour: -10 Wind speed must be at least 2 mph. > python WindChill.py Enter Fahrenheit temperature: 25.1278 Enter wind speed in miles per hour: 10 Fahrenheit report Temperature: 25.128 °F Wind speed: 10.000 mph Wind chill: 15.210 °F Celsius report Temperature: -3.818 °C Wind speed: 16.093 kph Wind chill: -9.328 °C > python WindChill.py Enter Fahrenheit temperature: 0.0 Enter wind speed in miles per hour: 35.9999 Fahrenheit report Temperature: 0.000 °F Wind speed: 36.000 mph Wind chill: -27.688 °F Celsius report Temperature: -17.778 °C Wind speed: 57.936 kph Wind chill: -33.160 °C >Notice these sample runs are from the command line; yours can run under IDLE or another IDE. However, the TA should be able to run your program file at the command level. Your output should be exactly like this for these input data. There is a single space after each colon and two spaces before the indented lines. Include blank lines as indicated.
Be sure to test your program before you submit it. It should also contain a header with the following format:
# File: WindChill.py # Student: # UT EID: # Course Name: CS303E # # Date: # Description of Program:
If you submit multiple times to Canvas, it will rename your file name
to something like WindChill-1.py, WindChill-2.py, etc.
Don't worry about that; we'll grade the latest version.
For many of the assignments this semester, we'll say that you can assume certain things about the inputs usually because you don't yet have the skills necessary to check for certain errors. But if you get a programming job, you should always validate the inputs as much as possible. In general, it's bad programming practice to allow bad inputs to crash your program; it means that your program is not robust. Later we'll insist that you "validate" some inputs, meaning to assure that they do meet specifications.
Format vs. round: A floating point number is stored in memory with a certain precision (usually 32 bits or 64 bits). For example math.pi is 3.141592653589793. Since pi is an irrational, this is still an approximation; there is no finite decimal expansion that represents pi exactly. So when you want to print pi (or any other float) you need to decide how much of the representation you want to retain.
format() is the way you tell Python how you'd like a number printed. It generates a string representation suitable for printing. Notice it doesn't change anything in memory or store a new number. If you want pi printed to 4 decimal places you might do:
>>> math.pi 3.141592653589793 >>> format(math.pi, ".4f") '3.1416' >>> math.pi 3.141592653589793
round() is a way of generating a new number that you can then store in memory. If you then print it, Python will not display trailing zeros. So round() is not a way to get a certain precision printed.
>>> round(math.pi, 4) 3.1416 >>> math.pi # you didn't change pi 3.141592653589793 >>> x = 2.5002 >>> format(x, ".2f") '2.50' >>> y = round(x, 2) >>> x 2.5002 >>> y 2.5Bottom line: for printing use format(). Only use round() if you need a new number that is an approximation of the original.