Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format code with Autopep8, Black, ClangFormat, dotnet-format, Go fmt, Gofumpt, Google Java Format, isort, Ktlint, PHP CS Fixer, Prettier, RuboCop, Ruff Formatter, Rustfmt, Scalafmt, StandardJS, StandardRB, swift-format and Yapf #117

Merged
merged 1 commit into from
May 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions banking/transaction_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging


def deposit(account_id: int, amount: float) -> bool:
"""
Deposit an amount into an account.
Expand All @@ -18,13 +19,14 @@ def deposit(account_id: int, amount: float) -> bool:
account = get_account_by_id(account_id)
if amount < 0:
raise ValueError("Amount cannot be negative")
account['balance'] += amount
account["balance"] += amount
save_account(account)
return True
except Exception as e:
logging.error(f"Error depositing into account {account_id}: {e}")
return False


def withdraw(account_id: int, amount: float) -> bool:
"""
Withdraw an amount from an account.
Expand All @@ -41,15 +43,16 @@ def withdraw(account_id: int, amount: float) -> bool:
account = get_account_by_id(account_id)
if amount < 0:
raise ValueError("Amount cannot be negative")
if account['balance'] < amount:
if account["balance"] < amount:
raise ValueError("Insufficient balance")
account['balance'] -= amount
account["balance"] -= amount
save_account(account)
return True
except Exception as e:
logging.error(f"Error withdrawing from account {account_id}: {e}")
return False


def transfer(from_account_id: int, to_account_id: int, amount: float) -> bool:
"""
Transfer an amount between two accounts.
Expand All @@ -63,7 +66,9 @@ def transfer(from_account_id: int, to_account_id: int, amount: float) -> bool:
bool: True if the transfer was successful, False otherwise.
"""
try:
logging.info(f"Transferring {amount} from account {from_account_id} to account {to_account_id}")
logging.info(
f"Transferring {amount} from account {from_account_id} to account {to_account_id}"
)
if not withdraw(from_account_id, amount):
return False
if not deposit(to_account_id, amount):
Expand Down
Loading