A Temperature class

Write a small class that holds a temperature.

What to build

A class with one attribute and two methods.

Requirements

  • Temperature(celsius) stores the value.
  • fahrenheit() returns celsius * 9 / 5 + 32.
  • is_freezing() returns True at 0 degrees or below.

Input

One whole number.

Output

Two lines: the Fahrenheit value with one decimal, then freezing or not freezing.

Constraints

The number is from -100 to 100.

Example

Input:

100

Output:

212.0
not freezing

Why it works

Each object carries its own temperature, so its methods need no parameters.

Examples

Example 1 · Input
100
Expected output
212.0
not freezing
Example 2 · Input
-5
Expected output
23.0
freezing

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Store the value on self in __init__.

Hint 2

A method can use self.celsius.

Solution

Show one correct solution (try it yourself first)
class Temperature:
    def __init__(self, celsius):
        self.celsius = celsius

    def fahrenheit(self):
        return self.celsius * 9 / 5 + 32

    def is_freezing(self):
        return self.celsius <= 0

t = Temperature(int(input()))
print(f"{t.fahrenheit():.1f}")
print("freezing" if t.is_freezing() else "not freezing")

Lesson: Classes and objects →