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

Function celsius_to_fahrenheit

conversions/temperature_conversions.py:4–29  ·  view source on GitHub ↗

Convert a given value from Celsius to Fahrenheit and round it to 2 decimal places. Wikipedia reference: https://en.wikipedia.org/wiki/Celsius Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit >>> celsius_to_fahrenheit(273.354, 3) 524.037 >>> celsius_to_fahrenhei

(celsius: float, ndigits: int = 2)

Source from the content-addressed store, hash-verified

2
3
4def celsius_to_fahrenheit(celsius: float, ndigits: int = 2) -> float:
5 """
6 Convert a given value from Celsius to Fahrenheit and round it to 2 decimal places.
7 Wikipedia reference: https://en.wikipedia.org/wiki/Celsius
8 Wikipedia reference: https://en.wikipedia.org/wiki/Fahrenheit
9
10 >>> celsius_to_fahrenheit(273.354, 3)
11 524.037
12 >>> celsius_to_fahrenheit(273.354, 0)
13 524.0
14 >>> celsius_to_fahrenheit(-40.0)
15 -40.0
16 >>> celsius_to_fahrenheit(-20.0)
17 -4.0
18 >>> celsius_to_fahrenheit(0)
19 32.0
20 >>> celsius_to_fahrenheit(20)
21 68.0
22 >>> celsius_to_fahrenheit("40")
23 104.0
24 >>> celsius_to_fahrenheit("celsius")
25 Traceback (most recent call last):
26 ...
27 ValueError: could not convert string to float: 'celsius'
28 """
29 return round((float(celsius) * 9 / 5) + 32, ndigits)
30
31
32def celsius_to_kelvin(celsius: float, ndigits: int = 2) -> float:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected