2.0 KiB
2.0 KiB
Question 3: Simulating the Daily Temperature Changes in a Room
Scenario:
Imagine a room where the temperature changes throughout the day. The room is divided into a 3x3 grid, where each cell represents a section of the room. The temperature in the room starts at a uniform value, but it changes based on the time of day. The goal is to simulate how the temperature changes in the room over a 24-hour period.
Problem Statement:
You are required to write a program that simulates the temperature changes in the room.
The program should:
- Initialize the temperature of the room.
- Use nested loops to update the temperature of each section of the room at each hour.
- Use if-else statements to apply the temperature changes based on the time of day.
- Print the temperature distribution in the room at each hour.
- Use a while loop to simulate the temperature changes over a 24-hour period.
Assumptions:
- The room is a 3x3 grid.
- The initial temperature of the room is 20°C.
- The temperature increases by 1°C every hour from 6 AM to 6 PM.
- The temperature decreases by 1°C every hour from 6 PM to 6 AM.
- The simulation runs for 24 hours.
Instructions (for reference):
- Initialize a 3x3 grid representing the temperature of the room.
- Use nested loops to iterate through each section of the room.
- Use if-else statements to apply the temperature changes based on the time of day.
- Update the temperature of each section in the grid.
- Print the temperature distribution in the room at each hour.
- Use a while loop to simulate the temperature changes over 24 hours.
Deliverables:
- A well-commented code that simulates the temperature changes in the room.
- A brief explanation of how the code works.
Sample Output:
Enter the Room Temperature: 30 Enter the Number of Hours between 0-24: 3
Hour 0
29.0 29.0 29.0
29.0 29.0 29.0
29.0 29.0 29.0
Hour 1
28.0 28.0 28.0
28.0 28.0 28.0
28.0 28.0 28.0
Hour 2
27.0 27.0 27.0
27.0 27.0 27.0
27.0 27.0 27.0