CS303E Homework 3

Instructor: Dr. Bill Young
Due Date: Monday, September 15, 2025 at 11:59pm

Copyright © William D. Young. All rights reserved.

Wind chill (or wind chill factor) is the sensation of cold produced by the wind for a given air temperature on exposed skin. Air motion accelerates the rate of heat transfer from the body to the surrounding atmosphere, making it feel colder than the temperature might indicate. The wind chill value is always lower than the air temperature in the range where the formula is valid. When the apparent temperature is higher than the air temperature, the heat index is used instead.

Assignment

In this assignment, you'll write a program that accepts from the user two pieces of data: the Fahrenheit temperature and the wind speed in miles per hour. You can assume that the values entered are (strings representing) integer or floating point numbers; don't assume that they're in the right range. You'll compute the wind chill and print a nice report for both Fahrenheit and Celsius. For the Celsius report, you'll use kilometers per hour rather than miles per hour.

Wind chill is computed using the following formula:

    Twc = 35.74 + 0.6215T - 35.75V0.16 + 0.4275TV0.16
where 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/9
To 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.

Turning in the Assignment:

The program should be in a file named WindChill.py. Submit the file via Canvas before the deadline shown at the top of this page. Submit it to the assignment hw3 under the assignments sections by uploading your python file.

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.

Programming Tips:

You can assume. When an assignment says that "you can assume" something about the input, that just means that you don't have to check it. If the user enters an input that doesn't meet that assumption, the program can crash or behave badly. That's not your problem.

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.5
Bottom line: for printing use format(). Only use round() if you need a new number that is an approximation of the original.