This commit is contained in:
louiscklaw
2025-01-31 21:40:42 +08:00
parent 9a15bbea05
commit 04a4edce00
8 changed files with 308 additions and 0 deletions

11
saralai19981321/gitUpdate.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -ex
git add .
git commit -m"update akton,"
git push
echo "done"

11
saralai19981321/meta.md Normal file
View File

@@ -0,0 +1,11 @@
---
tags: python
---
# saralai19981321
你係想:
1. 我幫你做? (成品 + comment, $)
2. 我幫你做,解釋番點解要咁做? (成品 + comment + 解釋, $$)
3. side by side 我隔住你隻手做? ($$$)

8
saralai19981321/notes.md Normal file
View File

@@ -0,0 +1,8 @@
你係想:
1. 我幫你做? (成品 + comment, $)
2. 我幫你做,解釋番點解要咁做? (成品 + comment + 解釋, $$)
3. side by side 我隔住你隻手做? ($$$)
4. HKD300
5. HKD100 / hr

View File

@@ -0,0 +1,58 @@
#!/usr/bin/env python
import os,sys
from pprint import pprint
from math import sin, pi
import random
hours = 24
grid_num = 9
base_temperature=20
temperature_sections = []
def simulateTemperatureChange(hr_of_day, change_cofficient =1):
# 3. Use if-else statements to apply the temperature changes based on the time of day.
# morning (6-11)
# afternoon (12-17)
# evening (18-22)
# night (23-5)
if (hr_of_day >= 6 and hr_of_day <= 11):
change_cofficient = -1
elif (hr_of_day > 11 and hr_of_day <= 17):
change_cofficient = 3
elif (hr_of_day > 17 and hr_of_day <= 22):
change_cofficient = 2
else:
change_cofficient = 1
return base_temperature + (random.uniform(-change_cofficient ,change_cofficient) * sin(hr_of_day/24.0* pi))
def initRoomTemperature():
# 1. Initialize the temperature of the room.
return [[0]*grid_num]*hours
# 2. Use nested loops to update the temperature of each section of the room at each hour.
def updateTemperature():
# 5. Use a while loop to simulate the temperature changes over a 24-hour period.
hr_of_day = 0
while hr_of_day < hours:
for section in range(grid_num):
temperature_sections[hr_of_day][section] = simulateTemperatureChange(hr_of_day)
hr_of_day += 1
# 4. Print the temperature distribution in the room at each hour.
def printTemperatureOfRooms():
for hr_of_day in range(hours):
print(f'hour {hr_of_day+1}')
for section in range(0,grid_num,3):
print(f'{temperature_sections[hr_of_day][section]:.1f}', end=' ')
print(f'{temperature_sections[hr_of_day][section+1]:.1f}', end=' ')
print(f'{temperature_sections[hr_of_day][section+2]:.1f}', end=' ')
print()
print('')
temperature_sections=initRoomTemperature()
updateTemperature()
printTemperatureOfRooms()

View File

@@ -0,0 +1,61 @@
# 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
```

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env python
import os,sys
from pprint import pprint
from math import sin, pi
import random
# ## Instructions (for reference):
# 1. Initialize the height of the particle to 100 meters.
h = 100
# 2. Use a while loop to simulate the motion of the particle until it hits the ground.
# 3. Inside the while loop, use an if-else statement to check if the particle has hit the ground.
# 4. Update the height of the particle using the equation of motion: h = hinitial 1/2 * g * (t)2.
# 5. Print the height of the particle at each time step.
# 6. Use a for loop to iterate through the time steps.
# h = h - 1/2 * g * t^2
# 1. Initialize the height from which the particle is released.
t_step = float(input("Enter the time step in seconds: "))
h_current = float(input("Enter the height in meters: "))
h_initial = h_current
t_current = 0
while (h_current >= 0):
# 4. Print the height of the particle at each time step until it hits the ground.
print(f'Time: {t_current:.1f} s, Height: {h_current:.2f} m')
# 2. Use a loop to update the position of the particle at each time step.
t_current += t_step
h_current = h_initial - (1/2 * 9.8 * (t_current**2))
# 3. Use an if-else statement to check if the particle has hit the ground.
if (h_current < 0):
print(f'Time: {(t_current):.1f} s, Height: {0:.2f} m')
print(f'has hit the ground')
break

View File

@@ -0,0 +1,119 @@
# Question 04:
Simulating the Motion of a Particle in a Gravitational Field
## Scenario:
Imagine a particle is released from a certain height above the ground and is subject to gravitational acceleration. The particle falls freely under gravity until it hits the ground. For simplicity, assume that air resistance is negligible, and the only force acting on the particle is gravity.
## Problem Statement:
You are required to write a program that simulates the motion of the particle.
1. Initialize the height from which the particle is released.
2. Use a loop to update the position of the particle at each time step.
3. Use an if-else statement to check if the particle has hit the ground.
4. Print the height of the particle at each time step until it hits the ground.
## Assumptions:
- Gravitational acceleration (g) is 9.8 m/s².
- The time step (Δt) for the simulation is 0.1 seconds and t is the current time.
- The initial height (h) from which the particle is released is 100 meters.
- Assume velocity and mass are ZERO (for ease of programming)
## Instructions (for reference):
1. Initialize the height of the particle to 100 meters.
2. Use a while loop to simulate the motion of the particle until it hits the ground.
3. Inside the while loop, use an if-else statement to check if the particle has hit the ground.
4. Update the height of the particle using the equation of motion: h = hinitial 1/2 _ g _ (t)2.
5. Print the height of the particle at each time step.
6. Use a for loop to iterate through the time steps.
Deliverables:
- A well-commented code that simulates the motion of the particle.
- A brief explanation of how the code works.
### Sample Output 1:
```
Enter the time step in seconds: 0.1
Enter the height in meters: 1
Time: 0.0 s, Height: 1.00 m
Time: 0.1 s, Height: 0.95 m
Time: 0.2 s, Height: 0.80 m
Time: 0.3 s, Height: 0.56 m
Time: 0.4 s, Height: 0.22 m
Time: 0.5 s, Height: 0.00 m
The particle has hit the ground.
```
### Sample Output 2:
```
Enter the time step in seconds: 0.2
Enter the height in meters: 2
Time: 0.0 s, Height: 2.00 m
Time: 0.2 s, Height: 1.80 m
Time: 0.4 s, Height: 1.22 m
Time: 0.6 s, Height: 0.24 m
Time: 0.8 s, Height: 0.00 m
The particle has hit the ground.
```
### Sample Output 3:
```
Enter the time step in seconds: 0.1
Enter the height in meters: 100
Time: 0.0 s, Height: 100.0 m
Time: 0.1 s, Height: 99.95 m
Time: 0.2 s, Height: 99.80 m
Time: 0.3 s, Height: 99.56 m
Time: 0.4 s, Height: 99.22 m
Time: 0.5 s, Height: 98.78 m
Time: 0.6 s, Height: 98.24 m
Time: 0.7 s, Height: 97.60 m
Time: 0.8 s, Height: 96.86 m
Time: 0.9 s, Height: 96.03 m
Time: 1.0 s, Height: 95.10 m
Time: 1.1 s, Height: 94.07 m
Time: 1.2 s, Height: 92.94 m
Time: 1.3 s, Height: 91.72 m
Time: 1.4 s, Height: 90.40 m
Time: 1.5 s, Height: 88.97 m
Time: 1.6 s, Height: 87.46 m
Time: 1.7 s, Height: 85.84 m
Time: 1.8 s, Height: 84.12 m
Time: 1.9 s, Height: 82.31 m
Time: 2.0 s, Height: 80.40 m
Time: 2.1 s, Height: 78.39 m
Time: 2.2 s, Height: 76.28 m
Time: 2.3 s, Height: 74.08 m
Time: 2.4 s, Height: 71.78 m
Time: 2.5 s, Height: 69.37 m
Time: 2.6 s, Height: 66.88 m
Time: 2.7 s, Height: 64.28 m
Time: 2.8 s, Height: 61.58 m
Time: 2.9 s, Height: 58.79 m
Time: 3.0 s, Height: 55.90 m
Time: 3.1 s, Height: 52.91 m
Time: 3.2 s, Height: 49.82 m
Time: 3.3 s, Height: 46.64 m
Time: 3.4 s, Height: 43.36 m
Time: 3.5 s, Height: 39.97 m
Time: 3.6 s, Height: 36.50 m
Time: 3.7 s, Height: 32.92 m
Time: 3.8 s, Height: 29.24 m
Time: 3.9 s, Height: 25.47 m
Time: 4.0 s, Height: 21.60 m
Time: 4.1 s, Height: 17.63 m
Time: 4.2 s, Height: 13.56 m
Time: 4.3 s, Height: 9.40 m
Time: 4.4 s, Height: 5.14 m
Time: 4.5 s, Height: 0.77 m
Time: 4.6 s, Height: 0.00 m
The particle has hit the ground.
```

Binary file not shown.