boxcalculator 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from .core import (
|
|
2
|
+
calc_box,
|
|
3
|
+
calc_bottom_perimeter,
|
|
4
|
+
calc_space_diagonal,
|
|
5
|
+
calc_surface_area,
|
|
6
|
+
calc_total_edge_length,
|
|
7
|
+
calc_volume,
|
|
8
|
+
is_cube,
|
|
9
|
+
show_result,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__version__ = "0.0.1"
|
|
13
|
+
__all__ = [
|
|
14
|
+
"calc_box",
|
|
15
|
+
"calc_bottom_perimeter",
|
|
16
|
+
"calc_space_diagonal",
|
|
17
|
+
"calc_surface_area",
|
|
18
|
+
"calc_total_edge_length",
|
|
19
|
+
"calc_volume",
|
|
20
|
+
"is_cube",
|
|
21
|
+
"show_result",
|
|
22
|
+
]
|
boxcalculator/core.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""长方体计算核心函数。所有长度单位一致即可,结果单位随输入。"""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def _validate(length, width, height):
|
|
5
|
+
"""校验长、宽、高必须是大于 0 的数字。"""
|
|
6
|
+
for name, value in (("length", length), ("width", width), ("height", height)):
|
|
7
|
+
if not isinstance(value, (int, float)) or isinstance(value, bool):
|
|
8
|
+
raise TypeError(f"{name} 必须是 int 或 float,收到 {type(value).__name__}")
|
|
9
|
+
if value <= 0:
|
|
10
|
+
raise ValueError(f"{name} 必须大于 0,收到 {value}")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def calc_volume(length, width, height):
|
|
14
|
+
"""体积 = 长 × 宽 × 高。"""
|
|
15
|
+
_validate(length, width, height)
|
|
16
|
+
return length * width * height
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def calc_surface_area(length, width, height):
|
|
20
|
+
"""表面积 = 2 × (长×宽 + 长×高 + 宽×高)。"""
|
|
21
|
+
_validate(length, width, height)
|
|
22
|
+
return 2 * (length * width + length * height + width * height)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def calc_bottom_perimeter(length, width, height=None):
|
|
26
|
+
"""底面周长 = 2 × (长 + 宽),height 仅为保持调用一致而保留。"""
|
|
27
|
+
_validate(length, width, height if height is not None else 1)
|
|
28
|
+
return 2 * (length + width)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def calc_space_diagonal(length, width, height):
|
|
32
|
+
"""体对角线 = sqrt(长² + 宽² + 高²)。"""
|
|
33
|
+
_validate(length, width, height)
|
|
34
|
+
return (length**2 + width**2 + height**2) ** 0.5
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def calc_total_edge_length(length, width, height):
|
|
38
|
+
"""总棱长 = 4 × (长 + 宽 + 高)。"""
|
|
39
|
+
_validate(length, width, height)
|
|
40
|
+
return 4 * (length + width + height)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def is_cube(length, width, height):
|
|
44
|
+
"""长、宽、高相等时为正方体。"""
|
|
45
|
+
_validate(length, width, height)
|
|
46
|
+
return length == width == height
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def calc_box(length, width, height):
|
|
50
|
+
"""
|
|
51
|
+
长方体计算函数
|
|
52
|
+
:param length: 长
|
|
53
|
+
:param width: 宽
|
|
54
|
+
:param height: 高
|
|
55
|
+
:return: 体积, 表面积, 底面周长
|
|
56
|
+
"""
|
|
57
|
+
volume = calc_volume(length, width, height)
|
|
58
|
+
area = calc_surface_area(length, width, height)
|
|
59
|
+
bottom_perimeter = calc_bottom_perimeter(length, width, height)
|
|
60
|
+
return volume, area, bottom_perimeter
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def show_result(l, w, h):
|
|
64
|
+
"""返回格式化后的计算结果字符串。"""
|
|
65
|
+
vol, surf, peri = calc_box(l, w, h)
|
|
66
|
+
diagonal = calc_space_diagonal(l, w, h)
|
|
67
|
+
edges = calc_total_edge_length(l, w, h)
|
|
68
|
+
info = f"""
|
|
69
|
+
====长方体计算结果====
|
|
70
|
+
长:{l},宽:{w},高:{h}
|
|
71
|
+
体积 = {vol:.2f}
|
|
72
|
+
表面积 = {surf:.2f}
|
|
73
|
+
底面周长 = {peri:.2f}
|
|
74
|
+
体对角线 = {diagonal:.2f}
|
|
75
|
+
总棱长 = {edges:.2f}
|
|
76
|
+
是否正方体 = {is_cube(l, w, h)}
|
|
77
|
+
"""
|
|
78
|
+
return info
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: boxcalculator
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: 长方体计算工具包,计算体积、表面积、底面周长
|
|
5
|
+
Author-email: kskblzdjd <student@example.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# boxcalculator
|
|
16
|
+
|
|
17
|
+
长方体参数计算工具包:体积、表面积、底面周长、体对角线、总棱长、正方体判断。
|
|
18
|
+
|
|
19
|
+
## 安装
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install boxcalculator
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 使用
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from boxcalculator import calc_box, show_result
|
|
29
|
+
|
|
30
|
+
volume, area, perimeter = calc_box(2, 3, 4)
|
|
31
|
+
print(volume, area, perimeter) # 24 52 10
|
|
32
|
+
|
|
33
|
+
print(show_result(2, 3, 4)) # 格式化输出全部结果
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 接口
|
|
37
|
+
|
|
38
|
+
| 函数 | 说明 |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `calc_volume(l, w, h)` | 体积 |
|
|
41
|
+
| `calc_surface_area(l, w, h)` | 表面积 |
|
|
42
|
+
| `calc_bottom_perimeter(l, w, h)` | 底面周长 |
|
|
43
|
+
| `calc_space_diagonal(l, w, h)` | 体对角线 |
|
|
44
|
+
| `calc_total_edge_length(l, w, h)` | 总棱长 |
|
|
45
|
+
| `is_cube(l, w, h)` | 是否正方体 |
|
|
46
|
+
| `calc_box(l, w, h)` | 一次返回体积、表面积、底面周长 |
|
|
47
|
+
| `show_result(l, w, h)` | 返回格式化结果字符串 |
|
|
48
|
+
|
|
49
|
+
长、宽、高必须为大于 0 的数字,否则抛出 `TypeError` / `ValueError`。
|
|
50
|
+
|
|
51
|
+
## 许可证
|
|
52
|
+
|
|
53
|
+
MIT License
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
boxcalculator/__init__.py,sha256=VjU9y7iZI66Tortql_Lvk3lQ0P7FU3OWCKqsUUIRzMU,425
|
|
2
|
+
boxcalculator/core.py,sha256=A8GvTusym2hspzkDbnxOHXnn05p4_Y3GN9Jo-OFPHro,2636
|
|
3
|
+
boxcalculator-0.0.1.dist-info/licenses/LICENSE,sha256=5PXquzAmCE6TxIXq2xIQcly2AxRJHLSz710O6SIIz9I,1066
|
|
4
|
+
boxcalculator-0.0.1.dist-info/METADATA,sha256=l4QdjeapzgtdSJszBysg4PIQai7rqFEQppw5E4Jexyo,1476
|
|
5
|
+
boxcalculator-0.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
6
|
+
boxcalculator-0.0.1.dist-info/top_level.txt,sha256=xtbCRf1PnvCYqLouxsycimPWP1sWy5VLEHRhuoS7hww,14
|
|
7
|
+
boxcalculator-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kskblzdjd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
boxcalculator
|