Python is a versatile and popular programming language known for its simplicity and readability. It offers a wide range of built-in algorithms and data structures that make it a powerful tool for solving a variety of problems efficiently. Here, we'll discuss some essential algorithms and data structures in Python.
examples of algorithms:
class BankAccount:
def __init__(self, account_number, owner_name, balance=0):
self.account_number = account_number
self.owner_name = owner_name
self.balance = balance
def deposit(self, amount):
if amount > 0:
self.balance += amount
print(f"Deposited ${amount}. New balance: ${self.balance}")
else:
print("Invalid deposit amount. Please enter a positive value.")
def withdraw(self, amount):
if 0 < amount <= self.balance:
self.balance -= amount
print(f"Withdrew ${amount}. New balance: ${self.balance}")
else:
print("Insufficient funds or invalid withdrawal amount.")
def check_balance(self):
print(f"Account Holder: {self.owner_name}")
print(f"Account Number: {self.account_number}")
print(f"Balance: ${self.balance}")
# Example usage:
if __name__ == "__main__":
# Create two bank accounts
account1 = BankAccount("12345", "Alice", 1000)
account2 = BankAccount("67890", "Bob", 500)
# Perform transactions
account1.check_balance()
account1.deposit(500)
account1.withdraw(200)
account1.check_balance()
account2.check_balance()
account2.deposit(1000)
account2.withdraw(800)
account2.check_balance()