This exercise combines defining a function, parameters, arithmetic, and return.
The conversion from Fahrenheit to Celsius is:
celsius = (fahrenheit - 32) * 5 / 9
to_celsius with one parameter, fahrenheit.Reference points to check against:
to_celsius(212) returns 100.0 — water boilsto_celsius(32) returns 0.0 — water freezesRun your code to see the output, then press Submit.
import unittest
class TestToCelsius(unittest.TestCase):
def test_boiling_point_212_f_is_100_c(self):
self.assertAlmostEqual(to_celsius(212), 100.0)
def test_freezing_point_32_f_is_0_c(self):
self.assertAlmostEqual(to_celsius(32), 0.0)
def test_body_temperature_98_6_f_is_37_c(self):
self.assertAlmostEqual(to_celsius(98.6), 37.0)
def test_negative_40_is_the_same_in_both(self):
self.assertAlmostEqual(to_celsius(-40), -40.0)
def to_celsius(fahrenheit):
return (fahrenheit - 32) * 5 / 9
print(to_celsius(212))
print(to_celsius(32))
Sign in to join the discussion.
No comments yet. Be the first to ask a question.
Press Run to execute your code, or Submit to test and complete this problem.