In services.py
Write a function, cooling_effect(power: float, minutes: int),
that calculates how much temperature the fridge can reduce given the cooling power and duration.
The formula is:
temperature_drop = power * minutes
Example:
>>> cooling_effect(0.5, 10)
5.0
>>> cooling_effect(1.2, 3)
3.6
In services.py
Write a function, new_temperature(current: float, power: float, minutes: int),
that calculates the new internal temperature after cooling for a given number of minutes.
- Subtract the cooling effect from the current temperature.
- The temperature cannot go below 0.
Example:
>>> new_temperature(8.0, 0.5, 10)
3.0
>>> new_temperature(3.0, 1.0, 10)
0.0
In services.py
Write a function, temperature_status(temp: float),
that returns the condition of the fridge based on its current temperature:
- 0 - 4 (excluding 4) -> "too cold"
- 4 - 7 (excluding 7) -> "optimal"
- 7+ -> "too warm"
Example:
>>> temperature_status(2.0)
'too cold'
>>> temperature_status(5.0)
'optimal'
>>> temperature_status(9.5)
'too warm'
In services.py
Write a function, adjust_cooling(status: str), that determines the appropriate cooling power
based on the current temperature status:
- "too cold" -> 0.2
- "optimal" -> 0.5
- "too warm" -> 1.0
Example:
>>> adjust_cooling("too warm")
1.0
>>> adjust_cooling("optimal")
0.5
>>> adjust_cooling("too cold")
0.2
In main.py
Write a function, simulate_fridge(temp: float, minutes: int),
that simulates how the refrigerator behaves minute by minute.
For each minute:
- Determine the current status (too cold, optimal, too warm)
- Print the minute, temperature, and status
- Adjust the cooling power based on the temperature status
- Update the temperature for the next minute
Example:
>>> simulate_fridge(9.0, 9)
Minute 0: Temp = 9.0 (too warm)
Minute 1: Temp = 8.0 (too warm)
Minute 2: Temp = 7.0 (too warm)
Minute 3: Temp = 6.0 (optimal)
Minute 4: Temp = 5.5 (optimal)
Minute 5: Temp = 5.0 (optimal)
Minute 6: Temp = 4.5 (optimal)
Minute 7: Temp = 4.0 (optimal)
Minute 8: Temp = 3.5 (too cold)
Minute 9: Temp = 3.3 (too cold)