Temperature Property Class
Create a Temperature class with a celsius attribute and a fahrenheit property that automatically calculates Fahrenheit from the stored Celsius value.
What the problem means: fahrenheit shouldn't be stored separately — it should always be computed live from celsius, and accessed like a plain attribute (no parentheses).
Approach: store celsius directly in init; define fahrenheit as a method decorated with @property that returns celsius * 9/5 + 32.
Input: One line: a Celsius temperature.
Output: One line: the Fahrenheit equivalent.
25
77.0
- -273.15 <= celsius <= 1000
Hint 1
The formula is F = C * 9/5 + 32.
Hint 2
@property above fahrenheit means it's accessed as Temperature(c).fahrenheit — no parentheses after fahrenheit.
@property turns fahrenheit into something read like a plain attribute rather than a method call. Its body just applies the standard conversion formula to self.celsius every time it's accessed, so the Fahrenheit value is always in sync with whatever celsius currently holds.
Related Problems
- Even Number GeneratorEasy · pythonSolve Problem
- Sort Students by MarksEasy · pythonSolve Problem
- Call Counter DecoratorMedium · pythonSolve Problem