原创

```python

温馨提示:
本文最后更新于 2024年07月24日,已超过 252 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

```python """ 这个模块包含一些有用的函数。

Example: >>> add(2, 3) 5 """

def add(x, y): """ 将两个数相加。

Args: x: 第一个数。 y: 第二个数。

Returns: 两个数的和。

Raises: TypeError: 如果输入不是数字。 """ if not isinstance(x, (int, float)) or not isinstance(y, (int, float)): raise TypeError("输入必须是数字") return x + y

def subtract(x, y): """ 从第一个数中减去第二个数。

Args: x: 第一个数。 y: 第二个数。

Returns: 两个数的差。

Raises: TypeError: 如果输入不是数字。 """ if not isinstance(x, (int, float)) or not isinstance(y, (int, float)): raise TypeError("输入必须是数字") return x - y

def multiply(x, y): """ 将两个数相乘。

Args: x: 第一个数。 y: 第二个数。

Returns: 两个数的积。

Raises: TypeError: 如果输入不是数字。 """ if not isinstance(x, (int, float)) or not isinstance(y, (int, float)): raise TypeError("输入必须是数字") return x * y

def divide(x, y): """ 将第一个数除以第二个数。

Args: x: 第一个数。 y: 第二个数。

Returns: 两个数的商。

Raises: TypeError: 如果输入不是数字。 ZeroDivisionError: 如果第二个数是0。 """ if not isinstance(x, (int, float)) or not isinstance(y, (int, float)): raise TypeError("输入必须是数字") if y == 0: raise ZeroDivisionError("不能除以0") return x / y ```

正文到此结束