Day 2: In class activities¶
1. Custom Functions¶
Let's create a function temp_conv()
, which converts the temperature in Fahrenheit (input) to the temperature in Kelvin (output).
-
We could perform a two-step calculation: first convert from Fahrenheit to Celsius, and then convert from Celsius to Kelvin.
-
The formula for these two calculations are as follows: temp_c = (temp_f - 32) * 5 / 9; temp_k = temp_c + 273.15.
-
if your input is 70, the result of
temp_conv(70)
should be 294.2611.
2. Nesting Functions¶
Now we want to round the temperature in Kelvin (output of temp_conv()
) to a single decimal place. Use the round()
function with the newly-created temp_conv()
function to achieve this in one line of code. If your input is 70, the output should now be 294.3.
Attribution notice
-
This lesson has been developed by members of the teaching team at the Harvard Chan Bioinformatics Core (HBC). These are open access materials distributed under the terms of the Creative Commons Attribution license (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.
-
The materials used in this lesson are adapted from work that is Copyright © Data Carpentry (http://datacarpentry.org/).
-
All Data Carpentry instructional material is made available under the Creative Commons Attribution license (CC BY 4.0).