Skip to content
Snippets Groups Projects
Commit f12d6235 authored by joberembt's avatar joberembt
Browse files

Upload New File

parent 871dd29a
No related branches found
No related tags found
No related merge requests found
class account:
"""This class creates account objects with basic methods to deposit, withdraw, get balance, and get name."""
def __init__(self, name):
"""This constructor initializes the account object with a private account name and a balance of 0."""
self.__account_name = name # private data variable for account holder name initialized using double underscore __
self.__account_balance = 0 # private data variable for account balance initialized to 0
def deposit(self, amount):
"""This method adds the specified amount to the account balance."""
if amount > 0: # checking that the amount is positive
self.__account_balance += amount # updating the account balance by adding the deposited amount
return True # return True if the deposit was successful
else:
return False # return False if the deposit was unsuccessful
def withdraw(self, amount):
"""This method subtracts the specified amount from the account balance."""
if amount > 0: # checking that the amount is positive
if amount <= self.__account_balance: # checking that the withdrawal amount is less than or equal to the account balance
self.__account_balance -= amount # updating the account balance by subtracting the withdrawn amount
return True # return True if the withdrawal was successful
else:
return False # return False if the withdrawal was unsuccessful
else:
return False # return False if the withdrawal amount is not positive
def get_balance(self):
"""This method returns the account balance."""
return self.__account_balance # return the account balance
def get_name(self):
"""This method returns the account holder's name."""
return self.__account_name # return the account holder's name
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment