Essays
Topics
Writing Tool
Machine Learning AI
ChatGPT
US History
Presidents of the United States
Joseph Robinette Biden
Donald Trump
Barack Obama
US States
States Ranked by Size & Population
States Ranked by Date
IPL
>
Accounting
>
일곱.pdf
일곱
.pdf
School
University of British Columbia
*
*We aren't endorsed by this school
Course
CPSC 100
Subject
Accounting
Date
Jan 14, 2025
Pages
2
Uploaded by BaronRabbit3932
7. Bank Account Manager
Python Code
:
python
Copy code
class BankAccount:
def __init__(self, name, balance=0):
self.name = name
self.balance = balance
def deposit(self, amount):
self.balance += amount
print(f"${amount} deposited. New balance: ${self.balance}")
def withdraw(self, amount):
if amount > self.balance:
print("Insufficient funds!")
else:
self.balance -= amount
print(f"${amount} withdrawn. New balance:
${self.balance}")
def display_balance(self):
print(f"Account holder: {self.name}, Balance:
${self.balance}")
def main():
name = input("Enter account holder's name: ")
account = BankAccount(name)
while True:
print("\nOptions: [1] Deposit [2] Withdraw [3] Check Balance
[4] Exit")
choice = input("Choose an option: ")
if choice == "1":
amount = float(input("Enter deposit amount: "))
account.deposit(amount)
elif choice == "2":
amount = float(input("Enter withdrawal amount: "))
account.withdraw(amount)
elif choice == "3":
account.display_balance()
elif choice == "4":
break
else:
print("Invalid choice!")
main()