Created
May 23, 2017 15:18
-
-
Save rickyhai11/100b9b1287db24bf891ad13f92515925 to your computer and use it in GitHub Desktop.
inherit_test created by rickyhai11 - https://repl.it/INMl/16
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
def is_authorized(f): | |
def wrraper(self, *args, **kwargs): | |
if self._is_authorized: | |
return f(self, *args, **kwargs) | |
print ("you are not authorized") | |
return wrraper | |
class Account(object): | |
''' | |
An object that represents a bank account | |
''' | |
def __init__(self, name, pin, balance=0.0, overdraft_limit = 20): | |
self.name = name | |
self.pin =pin | |
self.balance =balance | |
self.overdraft_limit = overdraft_limit | |
self._is_authorized =False | |
def login(self, pin): | |
if self.pin == pin: | |
self._is_authorized =True | |
print ("successfully") | |
return self._is_authorized | |
print ("login failed") | |
self._is_authorized =False | |
@is_authorized | |
def withdraw(self, amount): | |
if self.balance - amount < self.overdraft_limit: | |
print ("your transaction failed. overdraft limit is exceeded") | |
if self.balance -amount < 0.0: | |
print("your money is insufficient. Would you like to use overdraft money ? y/n") | |
answer = input("") | |
if answer is not "y": | |
return | |
self.balance -=amount | |
def deposit(self, amount): | |
self.balance +=amount | |
def print_balance(self): | |
print ("your balance: {%d}" %self.balance) | |
myaccount = Account('ricky', 1234, 10) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment