Difference between revisions of "Wind Chill"

From CompSciWiki
Jump to: navigation, search
(Completed the Wind chill program.)
(reworded a sentence in step 4)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Template:1010ExtraLabs
 
{{Template:1010ExtraLabs
 
|Chapter_TOC=[[Extra Labs]]
 
|Chapter_TOC=[[Extra Labs]]
|Introduction=In Winnipeg , it is noted that wind can make the air temperature even much colder. Write a program that will uses '''input''' to read in an air temperature and a wind speed. Then use the formula below to calculate and output the windchill.
+
|Introduction=In 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.
 
:<math>T_{wc}=13.12 + 0.6215 T_a-11.37 V^{0.16} + 0.3965 T_a V^{0.16}\,\!</math>
 
:<math>T_{wc}=13.12 + 0.6215 T_a-11.37 V^{0.16} + 0.3965 T_a V^{0.16}\,\!</math>
  
Line 9: Line 9:
 
|Body=
 
|Body=
  
===[[Step 1: Get inputs/outputs needed to solve the problem ]]===
+
===Step 1: Get inputs/outputs needed to solve the problem===
  
You will need the following in order to solve this problem.
+
You will need the following variables in order to solve this problem.
<li>location - The location at which you want to calculate the windchill.
+
* location - The location at which you want to calculate the windchill.
<li>temperatue - The temperature of your desired location
+
* temperatue - The temperature of your desired location
<li>windSpeed - The windSpeed at your desired location
+
* windSpeed - The windSpeed at your desired location
<li>input - Used to prompt the user for input
+
* input - Used to prompt the user for input
<li>raw_input - Used to prompt the user for input
+
* raw_input - Used to prompt the user for input
<li>windChill - The calculated wind chill of your desired location
+
* windChill - The calculated wind chill of your desired location
  
===[[Step 2: Write the program]]===
+
===Step 2: Write the program===
 
   
 
   
 
{{CodeBlock
 
{{CodeBlock
Line 42: Line 42:
 
}}
 
}}
  
===[[Step 3: Display the output of the program]]===
+
===Step 3: Display the output of the program===
  
 
{{OutputBlock
 
{{OutputBlock
Line 54: Line 54:
 
}}
 
}}
  
===[[Step 4: Contrast with Calculating Area in program a day example]]===
+
===Step 4: Contrast with windChill program in Program a Day example===
  
This Python program performs exactly the same function as the Java Calculate area program in Program a Day.
+
This Python program produces the same output as the Java WindChill program in [[Program_a_day|Program-A-Day]],
But, there only some slight differences as shown below.
+
but there are some differences which are described below.
<li>Python uses x**y as its power math operator whereas Java uses Math.pow(x,y)
+
* Python uses x**y as its Math power operator whereas Java uses Math.pow(x,y)
<li>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
+
* 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
<li>In the print statements, Python specifies the format(%f = float data type) some variable.
+
* In the print statements, Python specifies the format(%f = float data type) of some variable.
 
}}
 
}}

Latest revision as of 05:00, 5 April 2012

COMP 1010 Home > Back to Extra Labs

Introduction

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

<math>T_{wc}=13.12 + 0.6215 T_a-11.37 V^{0.16} + 0.3965 T_a V^{0.16}\,\!</math>
where <math>T_{wc}\,\!</math> is the wind chill index based on the Celsius scale, <math>T_a\,\!</math> is the air temperature in °C, and <math>V\,\!</math> is the air speed in km/h.
Equation taken from Wikipedia which cites http://www.msc.ec.gc.ca/education/windchill/science_equations_e.cfm

Step 1: Get inputs/outputs needed to solve the problem

You will need the following variables 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 produces the same output as the Java WindChill program in Program-A-Day, but there are some differences which are described 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.