MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / kelvin_to_fahrenheit

Function kelvin_to_fahrenheit

conversions/temperature_conversions.py:194–215  ·  view source on GitHub ↗

Convert a given value from Kelvin to Fahrenheit and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit >>> kelvin_to_fahrenheit(273.354, 3) 32.367 >>> kelvin_to_fahrenheit(273

(kelvin: float, ndigits: int = 2)

Source from the content-addressed store, hash-verified

192
193
194def kelvin_to_fahrenheit(kelvin: float, ndigits: int = 2) -> float:
195 """
196 Convert a given value from Kelvin to Fahrenheit and round it to 2 decimal places.
197 Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin
198 Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit
199
200 >>> kelvin_to_fahrenheit(273.354, 3)
201 32.367
202 >>> kelvin_to_fahrenheit(273.354, 0)
203 32.0
204 >>> kelvin_to_fahrenheit(273.15)
205 32.0
206 >>> kelvin_to_fahrenheit(300)
207 80.33
208 >>> kelvin_to_fahrenheit("315.5")
209 108.23
210 >>> kelvin_to_fahrenheit("kelvin")
211 Traceback (most recent call last):
212 ...
213 ValueError: could not convert string to float: 'kelvin'
214 """
215 return round(((float(kelvin) - 273.15) * 9 / 5) + 32, ndigits)
216
217
218def kelvin_to_rankine(kelvin: float, ndigits: int = 2) -> float:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected