module2 module

class module2.BankAccount(account_number, initial_balance=0.0)

Bases: object

A simple bank account class to manage balance and transactions.

account_number

The account number of the bank account.

Type:

str

balance

The current balance of the bank account.

Type:

float

Example

>>> account = BankAccount('123456789', 1000.0)
>>> account.deposit(500.0)
>>> account.get_balance()
1500.0
>>> account.withdraw(200.0)
>>> account.get_balance()
1300.0
>>> account.withdraw(2000.0)  # Raises ValueError: Insufficient balance.
deposit(amount)

Deposits a specified amount into the bank account.

Parameters:

amount (float) – The amount to deposit. Must be positive.

Raises:

ValueError – If the deposit amount is not positive.

Return type:

None

Example

>>> account = BankAccount('123456789', 1000.0)
>>> account.deposit(500.0)
>>> account.get_balance()
1500.0
get_balance()

Retrieves the current balance of the bank account.

Returns:

The current balance of the account.

Return type:

float

Example

>>> account = BankAccount('123456789', 1000.0)
>>> account.get_balance()
1000.0
withdraw(amount)

Withdraws a specified amount from the bank account.

Parameters:

amount (float) – The amount to withdraw. Must be positive and less than or equal to the current balance.

Raises:

ValueError – If the withdrawal amount is not positive or exceeds the current balance.

Return type:

None

Example

>>> account = BankAccount('123456789', 1000.0)
>>> account.withdraw(200.0)
>>> account.get_balance()
800.0
>>> account.withdraw(2000.0)  # Raises ValueError: Insufficient balance.