Difference between revisions of "Wind Chill"
From CompSciWiki
(Edited intro (primarly the first sentence)) |
m (changed bullets from <li> to * for consistnecy with other wiki pages) |
||
Line 12: | Line 12: | ||
You will need the following in order to solve this problem. | You will need the following in order to solve this problem. | ||
− | + | * location - The location at which you want to calculate the windchill. | |
− | + | * temperatue - The temperature of your desired location | |
− | + | * windSpeed - The windSpeed at your desired location | |
− | + | * input - Used to prompt the user for input | |
− | + | * raw_input - Used to prompt the user for input | |
− | + | * windChill - The calculated wind chill of your desired location | |
===Step 2: Write the program=== | ===Step 2: Write the program=== | ||
Line 58: | Line 58: | ||
This Python program performs exactly the same function as the Java WindChill program in Program a Day. | This Python program performs exactly the same function as the Java WindChill program in Program a Day. | ||
But, there only some slight differences as shown below. | But, there only some slight differences as shown below. | ||
− | + | * Python uses x**y as its Math power operator whereas Java uses Math.pow(x,y) | |
− | + | * Python does not perform conversion to other types but Java uses for instance double x = Double.parseDouble(y) to convert y to double data type | |
− | + | * In the print statements, Python specifies the format(%f = float data type) of some variable. | |
}} | }} |
Revision as of 21:21, 4 April 2012
COMP 1010 Home > Back to Extra Labs
IntroductionIn Winnipeg, the wind can make the temperature even colder than it is without windchill. Write a program that uses input to read in an air temperature and a wind speed. Then, use the formula below to calculate and output the windchill.
|
---|
Step 1: Get inputs/outputs needed to solve the problem
You will need the following in order to solve this problem.
- location - The location at which you want to calculate the windchill.
- temperatue - The temperature of your desired location
- windSpeed - The windSpeed at your desired location
- input - Used to prompt the user for input
- raw_input - Used to prompt the user for input
- windChill - The calculated wind chill of your desired location
Step 2: Write the program
####################################################################### #This program is used to calculate the wind chill of a desired location #input location = raw_input("What is the location?") temperature = input("What is the current temperature in Celsius?") windSpeed = input("What is the wind speed in kms per hour?") #calculate windchill windchill = 13.12 + .6215*temperature- 11.37 * (windSpeed**0.16) + 0.3965 * temperature * (windSpeed ** 0.16) #output print "\n\nLocation: " + location print "Current Temperature: %f" % temperature + " Celsius" print "Wind Speed:%02f " % windSpeed + " km/h" print "Temperature with Windchill: %02f" % windchill print "Programmed by A. Student" print "**End of Program**"
Step 3: Display the output of the program
Location: Winnipeg Current Temperature: -10.0 Celsius Wind Speed: 30.0 km/h Temperature with Windchill: -19.52049803338773 Programmed by A. Student **End of Program**
Step 4: Contrast with windChill program in Program a Day example
This Python program performs exactly the same function as the Java WindChill program in Program a Day. But, there only some slight differences as shown below.
- Python uses x**y as its Math power operator whereas Java uses Math.pow(x,y)
- Python does not perform conversion to other types but Java uses for instance double x = Double.parseDouble(y) to convert y to double data type
- In the print statements, Python specifies the format(%f = float data type) of some variable.