Files
test/test.py

34 lines
702 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
def divide(a, b):
"""
除法函数,计算 a 除以 b 的结果。
参数:
a: 被除数
b: 除数
返回:
除法结果浮点数。如果除数为0返回 None 并打印错误信息。
"""
if b == 0:
print("错误除数不能为0")
return None
return a / b
if __name__ == "__main__":
# 测试示例
print("测试除法函数:")
# 正常情况
result1 = divide(10, 2)
print(f"10 ÷ 2 = {result1}")
# 除数为0的情况
result2 = divide(5, 0)
print(f"5 ÷ 0 = {result2}")
# 浮点数除法
result3 = divide(7, 3)
print(f"7 ÷ 3 = {result3}")
print("测试完成。")