Intermediate
A validated temperature property
Write a class Temperature whose __init__(self, celsius) does self.celsius = celsius, where celsius is a property. The property keeps the real number in self._celsius.
The setter raises ValueError if the value is below -273.15, and otherwise stores it.
Add a read-only property fahrenheit that returns celsius * 9 / 5 + 32.
What Check tests
Temperature(100).celsiusis 100Temperature(100).fahrenheitis 212- Creating one below absolute zero raises ValueError
- Exactly -273.15 is allowed
fahrenheitfollows later changes tocelsius- Assigning a bad value later also raises ValueError
fahrenheitcannot be assigned
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.