Untitled
unknown
plain_text
a year ago
1.6 kB
6
Indexable
class BankAccount:
def __init__(self, name, balance=0):
self.name = name
self.balance = balance
def deposit(self, amount):
if amount > 0:
self.balance += amount
print(f"Deposited ${amount}. New balance is ${self.balance}")
else:
print("Invalid deposit amount.")
def withdraw(self, amount):
if 0 < amount <= self.balance:
self.balance -= amount
print(f"Withdrew ${amount}. New balance is ${self.balance}")
else:
print("Insufficient funds.")
def check_balance(self):
print(f"Current balance for {self.name}: ${self.balance}")
# Example usage
if __name__ == "__main__":
print("Welcome to the Banking App")
account_name = input("Enter your name: ")
account = BankAccount(account_name)
while True:
print("\nMenu:")
print("1. Deposit")
print("2. Withdraw")
print("3. Check Balance")
print("4. Exit")
choice = input("Enter your choice (1-4): ")
if choice == "1":
amount = float(input("Enter amount to deposit: "))
account.deposit(amount)
elif choice == "2":
amount = float(input("Enter amount to withdraw: "))
account.withdraw(amount)
elif choice == "3":
account.check_balance()
elif choice == "4":
print("Thank you for using the Banking App.")
break
else:
print("Invalid choice. Please enter a number from 1 to 4.")
Editor is loading...