Skip to content

29. Temperature with Properties

Difficulty: Easy · Topic: OOP & classes

Write a class Temperature(celsius) with two properties:

Your code runs in CPython on our servers against 6 tests, including hidden ones.

Sample test

t = Temperature(25)
t.fahrenheit

Expected: 77.0

Hints

Hint 1Store a single value (Celsius) and compute the other: two stored values can drift apart.
Hint 2@celsius.setter defines what t.celsius = x does.
Hint 3Let the constructor assign through the property (self.celsius = celsius) so the check lives in one place.

Learn the concepts

More Python problems

All Python problems