添加数字比较函数
This commit is contained in:
25
test1.py
Normal file
25
test1.py
Normal file
@@ -0,0 +1,25 @@
|
||||
def compare_numbers(a, b):
|
||||
"""
|
||||
比较两个数字的大小并返回结果
|
||||
|
||||
参数:
|
||||
a: 第一个数字
|
||||
b: 第二个数字
|
||||
|
||||
返回:
|
||||
str: 比较结果字符串
|
||||
"""
|
||||
if a > b:
|
||||
return f"{a} 大于 {b}"
|
||||
elif a < b:
|
||||
return f"{a} 小于 {b}"
|
||||
else:
|
||||
return f"{a} 等于 {b}"
|
||||
|
||||
|
||||
# 测试代码
|
||||
if __name__ == "__main__":
|
||||
# 测试用例
|
||||
print(compare_numbers(5, 3))
|
||||
print(compare_numbers(2, 7))
|
||||
print(compare_numbers(4, 4))
|
||||
Reference in New Issue
Block a user