Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LAB
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
joberembt
LAB
Commits
f12d6235
Commit
f12d6235
authored
Apr 20, 2023
by
joberembt
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
871dd29a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
account.py
+57
-0
57 additions, 0 deletions
account.py
with
57 additions
and
0 deletions
account.py
0 → 100644
+
57
−
0
View file @
f12d6235
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment