@@ -103,36 +103,36 @@ and we have access to the value that we returned.
103103## Composing Functions
104104
105105Now that we've seen how to turn Fahrenheit into Celsius,
106- we can also write the function to turn Celsius into Kelvin :
106+ we can also write the function to turn Celsius into kelvins :
107107
108108``` python
109- def celsius_to_kelvin (temp_c ):
109+ def celsius_to_kelvins (temp_c ):
110110 return temp_c + 273.15
111111
112- print (' freezing point of water in Kelvin:' , celsius_to_kelvin (0 .))
112+ print (' freezing point of water in Kelvin:' , celsius_to_kelvins (0.0 ))
113113```
114114
115115``` output
116- freezing point of water in Kelvin : 273.15
116+ freezing point of water in kelvins : 273.15
117117```
118118
119- What about converting Fahrenheit to Kelvin ?
119+ What about converting Fahrenheit to kelvins ?
120120We could write out the formula,
121121but we don't need to.
122122Instead,
123123we can [ compose] ( ../learners/reference.md#compose ) the two functions we have already created:
124124
125125``` python
126- def fahr_to_kelvin (temp_f ):
126+ def fahr_to_kelvins (temp_f ):
127127 temp_c = fahr_to_celsius(temp_f)
128- temp_k = celsius_to_kelvin (temp_c)
128+ temp_k = celsius_to_kelvins (temp_c)
129129 return temp_k
130130
131- print (' boiling point of water in Kelvin :' , fahr_to_kelvin (212.0 ))
131+ print (' boiling point of water in kelvins :' , fahr_to_kelvins (212.0 ))
132132```
133133
134134``` output
135- boiling point of water in Kelvin : 373.15
135+ boiling point of water in kelvins : 373.15
136136```
137137
138138This is our first taste of how larger programs are built:
@@ -145,55 +145,56 @@ or the next person who reads it won't be able to understand what's going on.
145145## Variable Scope
146146
147147In composing our temperature conversion functions, we created variables inside of those functions,
148- ` temp ` , ` temp_c ` , ` temp_f ` , and ` temp_k ` .
148+ ` temp_c ` , ` temp_f ` , and ` temp_k ` .
149149We refer to these variables as [ local variables] ( ../learners/reference.md#local-variable )
150150because they no longer exist once the function is done executing.
151151If we try to access their values outside of the function, we will encounter an error:
152152
153153``` python
154- print (' Again, temperature in Kelvin was:' , temp_k)
154+ print (' Again, temperature in kelvins was:' , temp_k)
155155```
156156
157157``` error
158158---------------------------------------------------------------------------
159159NameError Traceback (most recent call last)
160160<ipython-input-1-eed2471d229b> in <module>
161- ----> 1 print('Again, temperature in Kelvin was:', temp_k)
161+ ----> 1 print('Again, temperature in kelvins was:', temp_k)
162162
163163NameError: name 'temp_k' is not defined
164164```
165165
166- If you want to reuse the temperature in Kelvin after you have calculated it with ` fahr_to_kelvin ` ,
166+ If you want to reuse the temperature in kelvins
167+ after you have calculated it with ` fahr_to_kelvins ` ,
167168you can store the result of the function call in a variable:
168169
169170``` python
170- temp_kelvin = fahr_to_kelvin (212.0 )
171- print (' temperature in Kelvin was:' , temp_kelvin )
171+ temp_kelvins = fahr_to_kelvins (212.0 )
172+ print (' temperature in kelvins was:' , temp_kelvins )
172173```
173174
174175``` output
175- temperature in Kelvin was: 373.15
176+ temperature in kelvins was: 373.15
176177```
177178
178- The variable ` temp_kelvin ` , being defined outside any function,
179+ The variable ` temp_kelvins ` , being defined outside any function,
179180is said to be [ global] ( ../learners/reference.md#global-variable ) .
180181
181182Inside a function, one can read the value of such global variables:
182183
183184``` python
184185def print_temperatures ():
185186 print (' temperature in Fahrenheit was:' , temp_fahr)
186- print (' temperature in Kelvin was:' , temp_kelvin )
187+ print (' temperature in kelvins was:' , temp_kelvins )
187188
188189temp_fahr = 212.0
189- temp_kelvin = fahr_to_kelvin (temp_fahr)
190+ temp_kelvins = fahr_to_kelvins (temp_fahr)
190191
191192print_temperatures()
192193```
193194
194195``` output
195196temperature in Fahrenheit was: 212.0
196- temperature in Kelvin was: 373.15
197+ temperature in kelvins was: 373.15
197198```
198199
199200## Tidying up
0 commit comments