Assignment 2: Python Functions and Classes¶
In [ ]:
Copied!
In [ ]:
Copied!
2. Write a function to convert temperature to fahrenheit¶
Include an optional keyword argument to specify whether the input is in celcius or kelvin. Call your previously defined functions if necessary.
In [ ]:
Copied!
3. Check that the outputs are sensible¶
by trying a few examples
In [ ]:
Copied!
In [ ]:
Copied!
4. Now write a function that converts from farenheit¶
and uses a keyword argument to specify whether you want the output in celcius or kelvin
In [ ]:
Copied!
5. Write a function that takes two arguments (feet and inches) and returns height in meters¶
Verify it gives sensible answers
In [ ]:
Copied!
In [ ]:
Copied!
6. Write a function takes one argument (height in meters) and returns two arguments (feet and inches)¶
(Consult the tutorial on numbers if you are stuck on how to implement this.)
In [ ]:
Copied!
In [ ]:
Copied!
7. Verify that the "round trip" conversion from and back to meters is consistent¶
Check for 3 different values of height in meters
In [ ]:
Copied!
Part IV: Classes¶
Write a class that represents a Location. The constructor class should accept the arguments name
, latitude
, and longitude
.
Check if the latitude is between -90 to 90, and the longitude is between -180 and 180. Raise ValueError if not.
You should implement a method to calculate its relative location to our ENR building:
relative_loc_from_ENR
: The lat/lon of ENR buidling is: 40.476˚N, 74.43˚W. Print out if the location is 1) to the north or south or ENR; (2)to the east or west of ENR.
In [ ]:
Copied!