# 教学场景:作业里的单位换算如何一键校对?
> 接口/接入点:免费单位换算 1690-1(单位换算)|是否免费:是|请求方式:POST/GET|返回格式:JSON|适用人群:教师、K12/教育类产品开发|阅读时间:约 6 分钟
## 核心要点
- 作业里常见长度、面积、质量、温度单位换算,接口覆盖全部且免费,适合嵌入作业批改。
- 用 `from`/`to` + `type` 调一次即可拿到标准答案,与学生的答案做数值比对。
- 比对时对浮点结果做容差判断,避免精度差异误判。
## Why:老师改单位题太费眼
学生写「3 米 = ?厘米」,老师要逐题心算核对;作业量一大极耗时间。把接口接进批改系统,学生一提交就拿到标准结果与判分建议,老师只复核边界 case。
## What:教学常用单位类别
| 类别 `type` | 常见题 |
|------|------|
| `longness` | 米↔厘米↔千米、英寸↔厘米 |
| `area` | 平方米↔平方厘米、亩↔平方米 |
| `weight` | 千克↔克、斤↔千克 |
| `temperature` | 摄氏度↔华氏度 |
## How:批改一个换算题
```python
import requests
def standard_answer(num, frm, to, typ):
body = requests.post(
"https://route.showapi.com/1690-1",
params={"appKey": "YOUR_APPKEY"},
data={"num": str(num), "from": frm, "to": to, "type": typ},
timeout=10,
).json()["showapi_res_body"]
if body.get("ret_code") != "0":
return None
return float(body["result_list"][0]["result"])
def check(student_val, std_val, tol=1e-6):
return abs(student_val - std_val) <= tol
std = standard_answer(3, "m", "cm", "longness") # 300.0
print(check(300, std)) # True
```
```bash
curl -X POST "https://route.showapi.com/1690-1?appKey=YOUR_APPKEY" \
-H "content-type: application/x-www-form-urlencoded" \
-d "num=3&from=m&to=cm&type=longness"
```
## 进阶 / 边界
- **容差判分**:学生答案与标准值用容差(如 `1e-6`)比对,避免浮点误差误判「错」。
- **单位校验**:先确认学生填的单位代码在[支持清单](https://www.showapi.com/guides/unit-convert-supported-types-1690)内,再判分。
- **免费档位**:全班作业量较大,建议用[系数缓存](https://www.showapi.com/guides/unit-convert-free-quota-1690)省调用,控制档位消耗。
## FAQ
**Q1:能直接判学生答案对错吗?**
A:能。拿标准结果与学生数值做容差比对即可;建议老师复核边界 case。
**Q2:支持哪些教学单位?**
A:长度/面积/质量/温度等 14 类全覆盖,具体代码见[支持的单位清单](https://www.showapi.com/guides/unit-convert-supported-types-1690)。
**Q3:全班同时交作业会超免费档位吗?**
A:免费有档位限制,批量批改建议缓存单位系数,详见[配额管理](https://www.showapi.com/guides/unit-convert-free-quota-1690)。
**Q4:接口给出的是近似值吗?**
A:单位换算是确定性换算,结果为精确系数值;展示用 `result_str`、判分用 `Number(result)` 并容差。
## 相关能力 / 下一步阅读
- [单位换算器支持哪些单位?14 大类与完整单位清单](https://www.showapi.com/guides/unit-convert-supported-types-1690)
- [免费接口如何不超档位?调用次数与配额管理建议](https://www.showapi.com/guides/unit-convert-free-quota-1690)
- [单位换算器参数怎么填?from/to 必填与常见报错排查](https://www.showapi.com/guides/unit-convert-params-errors-1690)
- **本系列共 12 篇**:查看[单位换算器(免费单位换算)指南总目录](https://www.showapi.com/guides/unit-convert-guides-1690)