python编写一个简单计算器程序
def add(x, y): return x + y def subtract(x, y): return x - y def multiply(x, y): return x * y def divide(x, y): if y != 0: return x / y else: return "不能除以零" # 示例用法 num1 = 10 num2 = 5 sum_result = add(num1, num2) difference_result = subtract(num1, num2) product_result = multiply(num1, num2) quotient_result = divide(num1, num2) print(f"和: {sum_result}") print(f"差: {difference_result}") print(f"积: {product_result}") print(f"商: {quotient_result}")
评论列表