-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
77 additions
and
70 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# 课后拓展参考答案 | ||
|
||
## 练习 1:模拟边缘设备温度监控 | ||
|
||
**任务描述**:编写一个程序,模拟边缘设备的温度监控功能。程序应当: | ||
|
||
+ 输入当前设备的摄氏温度。 | ||
+ 判断温度是否超过安全运行阈值(例如 70°C)。 | ||
+ 如果超过,输出警告信息:“警告:设备温度过高!”。 | ||
+ 如果未超过,输出信息:“设备温度正常。”。 | ||
+ 将摄氏温度转换为华氏温度并输出。 | ||
|
||
转换公式:$ F = C \times \frac{9}{5} + 32 $ | ||
|
||
<details> | ||
<summary>点击查看答案</summary> | ||
|
||
```python | ||
# 输入摄氏温度 | ||
celsius = float(input("请输入设备当前的摄氏温度: ")) | ||
|
||
# 判断温度是否超过安全阈值 | ||
if celsius > 70: | ||
print("警告:设备温度过高!") | ||
else: | ||
print("设备温度正常。") | ||
|
||
# 摄氏温度转换为华氏温度 | ||
fahrenheit = celsius * 9 / 5 + 32 | ||
|
||
# 输出结果 | ||
print(f"摄氏温度 {celsius}°C 对应的华氏温度为 {fahrenheit}°F") | ||
``` | ||
|
||
**说明**: | ||
|
||
+ 该程序首先接受用户输入的摄氏温度,并根据设定的温度阈值(70°C)判断设备是否安全运行。 | ||
+ 若温度超标,输出警告;否则,输出正常。 | ||
+ 程序最后还将摄氏温度转换为华氏温度并输出。 | ||
|
||
</details> | ||
|
||
--- | ||
|
||
### 练习 2:帧类型判断(关键帧与普通帧) | ||
|
||
**任务描述**:编写一个程序,输入当前帧的编号,判断它是关键帧(奇数编号)还是普通帧(偶数编号),并输出相应的信息。 | ||
|
||
+ 提示:使用取余运算符 `%`。 | ||
+ 使用条件语句输出不同的信息。 | ||
|
||
<details> | ||
<summary>点击查看答案</summary> | ||
|
||
```python | ||
# 输入当前帧编号 | ||
frame_number = int(input("请输入当前帧的编号: ")) | ||
|
||
# 判断帧类型 | ||
if frame_number % 2 == 0: | ||
print(f"帧 {frame_number} 是普通帧,执行标准处理。") | ||
else: | ||
print(f"帧 {frame_number} 是关键帧,执行高级处理。") | ||
``` | ||
|
||
**说明**: | ||
|
||
+ 该程序首先获取用户输入的帧编号。 | ||
+ 使用取余运算符 `%` 判断该编号是否为偶数,若为偶数则为普通帧,输出“执行标准处理”;若为奇数则为关键帧,输出“执行高级处理”。 | ||
+ 这是一个简单的条件判断练习,能够帮助理解如何使用条件语句和运算符。 | ||
|
||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.