Last active
November 2, 2017 06:49
-
-
Save sunnyeyez123/3319f46a9e5ab2628d2a8667b3d07824 to your computer and use it in GitHub Desktop.
This wasn't that tricky. I think I will modify this behave more like an ATM than just an account. It will allow the user to interact and specify withdraw/deposit amounts. I will also require a pin for their account. I can make it so different users can store their pins.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' A bank account experience that allows you to view the balance of, deposit to and withdraw from your account''' | |
class BankAccount(object): | |
balance = 0 | |
def __init__(self,name): | |
self.name = name | |
def __repr__(self): | |
return "%s's account. Balanace: %.2f" %(self.name, self.balance) | |
def show_balance(self): | |
print "Balance: %.2f" % self.balance | |
def deposit(self, amount): | |
if amount <= 0: | |
print "You can't deposit that amount" | |
return | |
else: | |
print "Depositing $%.2f..." % amount | |
self.balance += amount | |
self.show_balance() | |
def withdraw(self, amount): | |
if amount >self.balance: | |
print "You can't withdraw that amount" | |
return | |
else: | |
print "Withdrawing $%.2f..." % amount | |
self.balance -= amount | |
self.show_balance() | |
my_account = BankAccount("Jasmine") | |
print my_account | |
my_account.show_balance() | |
my_account.deposit(2000) | |
my_account.withdraw(1000) | |
print my_account |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment