Add divide function to test.py
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
18
test.py
18
test.py
@@ -4,7 +4,23 @@ def multiply(a, b):
|
|||||||
"""
|
"""
|
||||||
return a * b
|
return a * b
|
||||||
|
|
||||||
|
def divide(a, b):
|
||||||
|
"""
|
||||||
|
计算两个数字相除的结果并返回结果
|
||||||
|
处理除零错误
|
||||||
|
"""
|
||||||
|
if b == 0:
|
||||||
|
raise ValueError("除数不能为零")
|
||||||
|
return a / b
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 测试函数
|
# 测试函数
|
||||||
result = multiply(3, 4)
|
result = multiply(3, 4)
|
||||||
print(f"3 * 4 = {result}")
|
print(f"3 * 4 = {result}")
|
||||||
|
|
||||||
|
# 测试除法函数
|
||||||
|
try:
|
||||||
|
result = divide(10, 2)
|
||||||
|
print(f"10 / 2 = {result}")
|
||||||
|
except ValueError as e:
|
||||||
|
print(f"除法错误: {e}")
|
||||||
Reference in New Issue
Block a user