Skip to content
Snippets Groups Projects
Commit 1fdbda05 authored by Jack Pink's avatar Jack Pink
Browse files

initial commit of climate analysis code

parents
Branches
No related tags found
No related merge requests found
import sys
import temp_conversion
import signal
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
script = sys.argv[0]
assert len(sys.argv) == 2, script + ": requires filename"
filename = sys.argv[1]
climate_data = open(filename, 'r')
for line in climate_data:
data = line.split(',')
if data[0][0] == '#':
# don't want to process comment lines, which start with '#'
pass
else:
# extract our max temperature in Fahrenheit - 4th column
fahr = float(data[3])
# don't process invalid temperature readings of -9999
if fahr != -9999:
celsius = temp_conversion.fahr_to_celsius(fahr)
kelvin = temp_conversion.fahr_to_kelvin(fahr)
print(str(celsius)+", "+str(kelvin))
"""A library to perform temperature conversions"""
def fahr_to_celsius(fahr):
"""Convert Fahrenheit to Celsius.
Uses standard Fahrenheit to Celsius formula
Arguments:
fahr -- the temperature in Fahrenheit
"""
celsius = ((fahr - 32) * (5/9))
return celsius
def fahr_to_kelvin(fahr):
"""Convert Fahrenheight to Kelvin.
Uses standard Fahrenheit to Kelvin formula
Arguments:
fahr -- the temperature in Fahrenheit
"""
kelvin = fahr_to_celsius(fahr) + 273.15
return kelvin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment