Calculator Library

calculator.py

This module provides a simple calculator class to perform basic arithmetic operations.

class lib.calculator.Calculator(initial_value=0)[source]

A simple calculator class to demonstrate Sphinx documentation.

value

The current value stored in the calculator.

Type:

float

add(amount)[source]

Adds a number to the current value.

Parameters:

amount (float) – The number to be added to the current value.

Returns:

The updated value after addition.

Return type:

float

subtract(amount)[source]

Subtracts a number from the current value.

Parameters:

amount (float) – The number to be subtracted from the current value.

Returns:

The updated value after subtraction.

Return type:

float

multiply(factor)[source]

Multiplies the current value by a given factor.

Parameters:

factor (float) – The factor to multiply the current value by.

Returns:

The updated value after multiplication.

Return type:

float

divide(divisor)[source]

Divides the current value by a given divisor.

Parameters:

divisor (float) – The divisor to divide the current value by.

Returns:

The updated value after division.

Return type:

float

Raises:

ValueError – If division by zero is attempted.

square()[source]

Squares the current value.

Returns:

The square of the current value.

Return type:

float