DEV Community

Codes With Pankaj
Codes With Pankaj

Posted on

Example of the `calculator` module

calculator.py:

# calculator.py
# Module providing basic arithmetic operations
# Author: Pankaj from codeswithpankaj.com

def add(x, y):
    """
    Add two numbers.

    Parameters:
    x (int): The first operand.
    y (int): The second operand.

    Returns:
    int: The sum of x and y.
    """
    return x + y

def subtract(x, y):
    """
    Subtract one number from another.

    Parameters:
    x (int): The minuend.
    y (int): The subtrahend.

    Returns:
    int: The result of subtracting y from x.
    """
    return x - y
Enter fullscreen mode Exit fullscreen mode

main.py:

# main.py
# Example of using the calculator module from codeswithpankaj.com

import calculator

# Perform addition and subtraction
result_add = calculator.add(5, 3)
result_subtract = calculator.subtract(8, 4)

# Display the results
print("Addition:", result_add)
print("Subtraction:", result_subtract)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)