Files
004_comission/saralai19981321/task1/Q3/notes.md
louiscklaw 04a4edce00 update,
2025-01-31 21:40:42 +08:00

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:

  1. Initialize the temperature of the room.
  2. Use nested loops to update the temperature of each section of the room at each hour.
  3. Use if-else statements to apply the temperature changes based on the time of day.
  4. Print the temperature distribution in the room at each hour.
  5. 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):

  1. Initialize a 3x3 grid representing the temperature of the room.
  2. Use nested loops to iterate through each section of the room.
  3. Use if-else statements to apply the temperature changes based on the time of day.
  4. Update the temperature of each section in the grid.
  5. Print the temperature distribution in the room at each hour.
  6. 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