コード例 #1
0
 def create_account(self, account_type, account_number):
     '''
     Creates and returns a new account object with the given account type and account number
     Takes two strings as parameters
     '''
     # Try to retrieve an account with the same account number and, if it succeeds, we know
     # that number is already in use.
     account_number_exists = False
     try:
         Checking_Account.get(account_number=account_number)
         account_number_exists = True
     except:
         try:
             Savings_Account.get(account_number=account_number)
             account_number_exists = True
         except:
             try:
                 Brokerage_Account.get_account(account_number)
                 acount_number_exists = True
             except:
                 pass
     # Throw exception if account number is already in use
     if account_number_exists:
         raise Exception("Account Number is already in use")
     # Create a checking account if that's the account type
     if account_type == "checking":
         acct = Checking_Account(account_number=account_number).save()
     # Create a savings account if that's the account type
     elif account_type == "savings":
         acct = Savings_Account(account_number=account_number).save()
     # Create a brokerage account if that's the account type
     elif account_type == "brokerage":
         acct = Brokerage_Account(account_number=account_number).save()
     # If we don't have a matching account type, raise an exception
     else:
         raise Exception("Invalid Account Type")
     return acct
コード例 #2
0
 def create_account(self, account_type, account_number):
     '''
     Creates and returns a new account object with the given account type and account number
     Takes two strings as parameters
     '''
     # Try to retrieve an account with the same account number and, if it succeeds, we know
     # that number is already in use.
     account_number_exists = False
     try:
         Checking_Account.get(account_number=account_number)
         account_number_exists = True
     except:
         try:
             Savings_Account.get(account_number=account_number)
             account_number_exists = True
         except:
             try:
                 Brokerage_Account.get_account(account_number)
                 acount_number_exists = True
             except:
                 pass
     # Throw exception if account number is already in use
     if account_number_exists:
         raise Exception("Account Number is already in use")
     # Create a checking account if that's the account type
     if account_type == "checking":
         acct = Checking_Account(account_number=account_number).save()
     # Create a savings account if that's the account type
     elif account_type == "savings":
         acct = Savings_Account(account_number=account_number).save()
     # Create a brokerage account if that's the account type
     elif account_type == "brokerage":
         acct = Brokerage_Account(account_number=account_number).save()
     # If we don't have a matching account type, raise an exception
     else:
         raise Exception("Invalid Account Type")
     return acct
コード例 #3
0
    def get_account(self):
        '''
        Ask the user for an account number, and return a valid account
        '''
        acct = None
        account_number = input("Account Number: ")
        # Check Savings Accounts for a match
        try:
            return Savings_Account.get_account(account_number)
        except Savings_Account.DoesNotExist:
            # Check Checking Accounts for a match
            try:
                return Checking_Account.get_account(account_number)
            except Checking_Account.DoesNotExist:
                # Check Brokerage Accounts for a match
                try:
                    return Brokerage_Account.get_account(account_number)
                except Brokerage_Account.DoesNotExist:
                    print("Account not found")

        return acct
コード例 #4
0
 def set_acct(self, id):
     self.acct = Brokerage_Account.get_account(id)
コード例 #5
0
 def set_acct(self, id):
     self.acct = Brokerage_Account.get_account(id)