科学计算器多参数公式:用 add / product / 逗号分隔一次算多个数
# 科学计算器多参数公式:用 add / product / 逗号分隔一次算多个数
> 接口 免费科学计算器(apiCode 1699)· 接入点 科学计算器(1699-1)· 免费 · POST/GET · 返回 JSON · 适合 开发者 / 数据处理 · 阅读约 3 分钟
## 核心要点
- `num` 支持逗号 `,` 分隔的多个值,一次调用完成「一串数的求和 / 连乘」。
- `add`(加)与 `product`(乘)支持多参数:`add(2,3,4)=9`、`product(2,3,4)=24`。
- 二元运算(`divide`/`mod`/`square`/`sqrt`)只取前两个有效参数,多参数需自行分批。
## Why:为什么要用多参数
要算「1+2+3+…+100」或「一组数的总和」,没必要循环调 100 次接口。把数字用逗号拼进 `num`,一次请求搞定,省调用次数也省时间——尤其免费接口有[使用档次限制](https://www.showapi.com/free-api)时更划算。
## What:接口速览
| 项目 | 说明 |
|------|------|
| 请求地址 | `https://route.showapi.com/1699-1?appKey={your_appKey}` |
| 多参支持 | `add`、`product` 支持 2 个及以上;`divide`/`mod`/`square`/`sqrt` 取前 2 个 |
| 计费 | 免费 |
## How:一行算一串数
```python
import requests
APP_KEY = "YOUR_APPKEY"
def calc(num, op):
r = requests.post(
"https://route.showapi.com/1699-1",
params={"appKey": APP_KEY},
data={"num": num, "operation": op, "rad_or_ang": ""},
timeout=10
)
b = r.json()["showapi_res_body"]
return b["result"] if str(b.get("ret_code")) == "0" else f"失败: {b.get('remark')}"
nums = "2,3,4,5"
print(calc(nums, "add")) # 14.0 求和
print(calc(nums, "product")) # 120.0 连乘
```
### cURL
```bash
curl -X POST "https://route.showapi.com/1699-1?appKey=YOUR_APPKEY" \
-H "content-type: application/x-www-form-urlencoded" \
-d "num=2,3,4,5&operation=add&rad_or_ang="
```
## 返回示例与解析
| 调用 | 真实结果 | 说明 |
|------|---------|------|
| `add(2,3,4)` | `9.0` | 2+3+4 |
| `add(2,3,4,5)` | `14.0` | 支持 4 个及以上 |
| `product(2,3,4)` | `24.0` | 2×3×4 |
| `divide(10,2)` | `5.0` | 二元,取前两个 |
| `mod(10,3)` | `1.0` | 10 mod 3 |
## 进阶 / 边界
- **二元运算只吃前两个参数**:`divide(10,2,3)` 仍按 10/2 算,第三个被忽略。多组二元运算需分批调用。
- **参数个数上限**:文档未明确单次 `num` 上限,以官方档位说明为准;超长数组建议分批。
- **负数参与**:`num` 支持负号(如 `10,-2`),结合 `add` 可实现减法效果(详见[操作名速查](https://www.showapi.com/guides/calculator-operations-reference-1699) 的减法替代方案)。
## FAQ
**Q1:`add` / `product` 最多能几个数?**
文档未给硬上限,实测 4 个正常;更长建议分批调用,具体以官方档位为准。
**Q2:逗号前后能加空格吗?**
建议不加空格,`2,3,4` 而非 `2, 3, 4`,避免解析异常。
**Q3:怎么算一串数的平均值?**
先 `add` 求和,再自行除以个数;接口没有直接的平均操作名。
**Q4:`divide` 多个数怎么算连除?**
只取前两个(如 `10,2,5` → 10/2=5),连除需自行分步或本地算出结果。
## 相关能力 / 下一步阅读
- [科学计算器操作名速查](https://www.showapi.com/guides/calculator-operations-reference-1699) —— 全部操作名与参数个数
- [科学计算器:5 分钟接入](https://www.showapi.com/guides/calculator-quickstart-1699) —— 首次调用
- [科学计算器错误码排查](https://www.showapi.com/guides/calculator-error-codes-1699) —— 失败如何定位
- **本系列共 11 篇**:查看[科学计算器开发指南总目录](https://www.showapi.com/guides/calculator-guides-1699)