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

Function fahrenheit_to_kelvin

conversions/temperature_conversions.py:110–137  ·  view source on GitHub ↗

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

(fahrenheit: float, ndigits: int = 2)

Source from the content-addressed store, hash-verified

108
109
110def fahrenheit_to_kelvin(fahrenheit: float, ndigits: int = 2) -> float:
111 """
112 Convert a given value from Fahrenheit to Kelvin and round it to 2 decimal places.
113 Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit
114 Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin
115
116 >>> fahrenheit_to_kelvin(273.354, 3)
117 407.236
118 >>> fahrenheit_to_kelvin(273.354, 0)
119 407.0
120 >>> fahrenheit_to_kelvin(0)
121 255.37
122 >>> fahrenheit_to_kelvin(20.0)
123 266.48
124 >>> fahrenheit_to_kelvin(40.0)
125 277.59
126 >>> fahrenheit_to_kelvin(60)
127 288.71
128 >>> fahrenheit_to_kelvin(80)
129 299.82
130 >>> fahrenheit_to_kelvin("100")
131 310.93
132 >>> fahrenheit_to_kelvin("fahrenheit")
133 Traceback (most recent call last):
134 ...
135 ValueError: could not convert string to float: 'fahrenheit'
136 """
137 return round(((float(fahrenheit) - 32) * 5 / 9) + 273.15, ndigits)
138
139
140def fahrenheit_to_rankine(fahrenheit: float, ndigits: int = 2) -> float:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected