5.1 מחלקות פתרון

class BankAccount:
    def __init__(self, account_number, initial_balance):
        self.account_number = account_number
        self.balance = initial_balance

    def deposit(self, amount):
        self.balance += amount
        print(f"Deposited ${amount} into account {self.account_number}")

    def withdraw(self, amount):
        if amount <= self.balance:
            self.balance -= amount
            print(f"Withdrew ${amount} from account {self.account_number}")
        else:
            print("Insufficient funds")

    def get_balance(self):
        return self.balance

# Create two bank accounts
account1 = BankAccount(123456789, 1000)
account2 = BankAccount(987654321, 500)

# Perform transactions
account1.deposit(500)
account1.withdraw(200)
print("Account 1 Balance:", account1.get_balance())

account2.deposit(1000)
account2.withdraw(700)
print("Account 2 Balance:", account2.get_balance())

- נסה לשנות את הקוד כדי להוסיף תכונות נוספות כגון בדיקת יתרות שליליות או הצגת היסטוריית עסקאות.