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

Function celsius_to_kelvin

conversions/temperature_conversions.py:32–53  ·  view source on GitHub ↗

Convert a given value from Celsius to Kelvin and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Celsius Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin >>> celsius_to_kelvin(273.354, 3) 546.504 >>> celsius_to_kelvin(273.354, 0)

(celsius: float, ndigits: int = 2)

Source from the content-addressed store, hash-verified

30
31
32def celsius_to_kelvin(celsius: float, ndigits: int = 2) -> float:
33 """
34 Convert a given value from Celsius to Kelvin and round it to 2 decimal places.
35 Wikipedia reference: https://en.wikipedia.org/wiki/Celsius
36 Wikipedia reference: https://en.wikipedia.org/wiki/Kelvin
37
38 >>> celsius_to_kelvin(273.354, 3)
39 546.504
40 >>> celsius_to_kelvin(273.354, 0)
41 547.0
42 >>> celsius_to_kelvin(0)
43 273.15
44 >>> celsius_to_kelvin(20.0)
45 293.15
46 >>> celsius_to_kelvin("40")
47 313.15
48 >>> celsius_to_kelvin("celsius")
49 Traceback (most recent call last):
50 ...
51 ValueError: could not convert string to float: 'celsius'
52 """
53 return round(float(celsius) + 273.15, ndigits)
54
55
56def celsius_to_rankine(celsius: float, ndigits: int = 2) -> float:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected