コード例 #1
0
class User:  # declare a class and give it name User
    def __init__(self, username, email_address):
        self.name = username
        self.email = email_address
        self.account = BankAccount(int_rate=0.02, balance=0)

    def make_deposit(self, amount):
        self.account.deposit(amount)
        return self

    def make_withdrawl(self, amount):
        self.account.withdraw(amount)
        return self

    def display_user_balance(self):
        if self.account >= 0:
            print(f"User: {self.name}, Balance: ${round(self.account,2)}")
            return self
        else:
            print(f"User: {self.name}, Balance: -${round(self.account*-1,2)}")
            return self

    def transfer_money(self, other_user, amount):
        self.account.withdraw(amount)
        other_user.account.deposit(amount)
        print(
            f"{self.name} has successfully transferred ${amount} to {other_user.name}"
        )
        return self

#nina = User("Nina Gervaise Tompkin","*****@*****.**")
#guido = User("Guido Von Trapperson","*****@*****.**")
#dimitar = User("Dimitar Mi Ho","*****@*****.**")

    ninaAccount = BankAccount("0.006", "5000")
    guidoAccount = BankAccount("0.05", "1000")

    ninaAccount.deposit(400).deposit(12.99).deposit(35.23).withdraw(
        300).yield_interest().display_account_info()
    guidoAccount.deposit(200).deposit(300).withdraw(100).withdraw(
        40.23).withdraw(19.99).withdraw(
            99.99).yield_interest().display_account_info()


#nina.make_deposit(100).make_deposit(200).make_deposit(50).make_withdrawl(300).display_user_balance()

#dimitar.make_deposit(42.32).make_deposit(59.99).make_withdrawl(24.99).make_withdrawl(6.60).display_user_balance()

#guido.make_deposit(1024.41).make_withdrawl(543.20).make_withdrawl(42.31).make_withdrawl(245.99).display_user_balance()

#nina.transfer_money(guido,200).display_user_balance()
#guido.display_user_balance()
コード例 #2
0
def log_in(event):
    '''Function to log in to the banking system using a known account number and PIN.'''
    global account
    global pin_number
    global account_number
    filepath = ""

    pin_number = account_pin_entry.get()
    account_number = account_number_entry.get()
    filepath = filepath + account_number
    filepath = filepath + '.txt'
    try:
        ac_file = open(filepath, 'r')
        account.account_number = ac_file.readline().strip()
        account.pin_number = ac_file.readline().strip()
        account.balance = ac_file.readline().strip()
        account.interest_rate = ac_file.readline().strip()
        if not account.pin_number == pin_number:
            messagebox.showinfo("ERROR", "Invalid PIN")
            clear_details()
            account = BankAccount()
        else:
            transaction = ac_file.readline().strip()
            while transaction:
                account.transaction_list.append(transaction)
                transaction = ac_file.readline().strip()
            remove_all_widgets()
            create_account_screen()

    except IOError:
        messagebox.showinfo("ERROR", "Invalid Account Number")
        clear_details()
コード例 #3
0
def account(start_ammount):
    """
    Vytvoří účet s počátečním stavem 20000

    Fixture může používat jinou fixture
    """
    return BankAccount(start_ammount)
コード例 #4
0
ファイル: bankbranch.py プロジェクト: palandesupriya/python
    def CreateAccount(self, bWantCard):
        obj = BankAccount(500)
        BankBranch.dctBankAccount[obj.getAccountNumber()] = obj

        #objATM = ATM()
        #objATM.ApplyCard(obj.getAccountNumber(), bWantCard)
        return obj.getAccountNumber()
コード例 #5
0
def index():

    user = BankAccount(session['username'], 0)

    rec_trans = []

    for x in user.recents():
        a, b, c = x

        fromz = tz.tzutc()

        toz = tz.tzlocal()

        utc = datetime.strptime(b, '%Y-%m-%d %H:%M:%S.%f')

        utc = utc.replace(tzinfo=fromz)

        b = utc.astimezone(toz)

        rec_trans.append([
            str(b.date()) + ' ' + str(b.hour) + ':' + str(b.minute) + ':' +
            str(b.second),
            str(c)
        ])

    rec_trans = list(reversed(rec_trans))[0:9]
    return render_template('index.html',
                           amount=str(user.getBalance()),
                           username=session['username'],
                           recents=convert(rec_trans))
コード例 #6
0
 def do_new(self, line):
     '''Create an account'''
     if self.account_valid():
         raise RuntimeError("Account already exists.")
     else:
         line = line.strip()
         initial_balance = float(line) if len(line) > 0 else 0
         print "creating new account: initial balance =", initial_balance
         self.account = BankAccount(initial_balance)
コード例 #7
0
    def setUp(self):
        # Create a test BankAccount object
        self.account = BankAccount()

        # test for save file
        self.account.account_number = 1100
        self.account.pin_number = 1100

        # Provide it with some property values
        self.account.balance = 1000.0
コード例 #8
0
 def create_bank_account(self, account_id, balance):
     bank_account = BankAccount(
         account_id, 
         self.bank_id, 
         self.currency, 
         balance, 
         self.transaction_queue
     )
     self.bank_accounts[account_id] = bank_account
     logger.debug(f'{self.bank_id}: Created account: {account_id}')
     return bank_account
コード例 #9
0
def withdraw():
    if re.match(r'\d+', request.form['amount']):

        user = BankAccount(session['username'], 0)

        user.withdraw(float(request.form['amount']))

        return redirect(url_for('index'))

    else:

        return redirect(url_for('index'))
コード例 #10
0
def transfer():

    if re.match(r'\d+', request.form['amount']):

        user = BankAccount(session['username'])

        user.transfer(float(request.form['amount']), request.form['target'])

        return redirect(url_for('index'))

    else:

        return redirect(url_for('index'))
コード例 #11
0
def save_and_log_out():
    '''Function  to overwrite the account file with the current state of
       the account object (i.e. including any new transactions), remove
       all widgets and display the login screen.'''
    global account
    account.save_to_file()
    # Save the account with any new transactions

    # Reset the bank acount object
    account = BankAccount()
    # Reset the account number and pin to blank
    account_pin_entry.set('')
    account_number_var.set('')
    # Remove all widgets and display the login screen again
    remove_all_widgets()
コード例 #12
0
def main():

    #Getting user's beginning balance through input
    balance = float(input("Enter beginning balance: "))
    #Making an object of the BankAccount class with the balance as he beginning value
    account = BankAccount(balance)
    #Getting user's desired amount to deposit
    deposit = float(input("How much were you paid this week? "))
    #Depositing the user's desired amount from the bank account object
    account.deposit(deposit)
    #Printing account's balance
    print(account)
    print()

    #Getting user's desired amount to withdraw
    withdraw = float(input("How much would you like to withdraw? "))
    #Withdrawing the user's desired amount from the bank account object
    account.withdraw(withdraw)
    #Printing account's balance
    print(account)
コード例 #13
0
 def setUp(self):
     self.account = BankAccount("Niki", 1350, "$")
     self.second_account = BankAccount("Vayne", 0, '$')
     self.account_diff_curr = BankAccount('Georgi', 260, 'e')
コード例 #14
0
ファイル: user.py プロジェクト: twtseng/Dojo_Assignments
 def __init__(self, first_name: str, last_name: str):
     self.first_name = first_name
     self.last_name = last_name
     self.account = BankAccount(int_rate=.02, balance=0)
コード例 #15
0
 def test_balance(self):
     acc = BankAccount(100)
     self.assertEqual(100, acc.balance())
コード例 #16
0
def log_in(event):
    '''Function to log in to the banking system using a known account number and PIN.'''
    global account
    global pin_number_var
    global account_number_var
    # Create the filename from the entered account number with '.txt' on the end
    filename = str(account_number_var.get()) + '.txt'

    # Try to open the account file for reading

    try:
        # Open the account file for reading
        fopen = open(filename, 'r')

        # First line is account number

        account.account_number = int(fopen.readline())

        # Second line is PIN number, raise exceptionk if the PIN entered doesn't match account PIN read

        account.pin_number = int(fopen.readline())

        assert int(pin_number_var.get()) == account.pin_number

        # Read third and fourth lines (balance and interest rate)

        account.balance = float(fopen.readline())
        account.interest_rate = float(fopen.readline())

        # Section to read account transactions from file - start an infinite 'do-while' loop here
        while True:
            # Attempt to read a line from the account file, break if we've hit the end of the file. If we
            # read a line then it's the transaction type, so read the next line which will be the transaction amount.
            # and then create a tuple from both lines and add it to the account's transaction_list
            transac_list = []
            check = fopen.readline()
            if check == '':
                break
            transac_list.append(check)
            transac_list.append(float(fopen.readline()))
            account.transaction_list.append(tuple(transac_list))

        # Close the file now we're finished with it
        fopen.close()

        # Catch exception if we couldn't open the file or PIN entered did not match account PIN
    except FileNotFoundError:

        # Show error messagebox and & reset BankAccount object to default...
        messagebox.showerror("Error",
                             "Invalid account number - please try again!")

        account = BankAccount()  # account  balance wiil call here

        #  ...also clear PIN entry and change focus to account number entry

        pin_number_var.set('')
        account_number_var.set('')

        return
    except AssertionError:
        messagebox.showerror("Error", "Wrong PIN entered!")
        account = BankAccount()
        pin_number_var.set('')
        account_number_var.set('')
        return

    except ValueError:
        messagebox.showerror("Error", "Enter some pin!")
        account = BankAccount()
        pin_number_var.set('')
        account_number_var.set('')
        return
        # return the value here

    # Got here without raising an exception? Then we can log in - so remove the widgets and display the account screen

    remove_all_widgets()
    create_account_screen()
コード例 #17
0
 def __init__(self):
     self._checkings = BankAccount()
     self._savings = BankAccount()
コード例 #18
0
 def __init__(self, name, email):
     self.name = name
     self.email = email
     self.account_balance = 0
     self.account = BankAccount(int_rate=0.02, balance=0)
コード例 #19
0
from bankaccount import BankAccount

hauptkonto = BankAccount("DE123", "Marko")

sparkonto = BankAccount("DE4432", "Marko")

print(hauptkonto.buchungen)
print(hauptkonto.iban)
print(sparkonto.owner_name)

hauptkonto.buchen(1234, "EUR", "Gehalt")
hauptkonto.buchen(-12, "EUR", "Mittagessen")

print(hauptkonto.buchungen)
print(hauptkonto.getbalance())
コード例 #20
0
ファイル: main.py プロジェクト: AviRanaMagar/fedunicheckout
# The balance label and associated variable
balance_var = tk.StringVar()
balance_var.set('Balance: $0.00')
balance_label = tk.Label(win, textvariable=balance_var)

# The Entry widget to accept a numerical value to deposit or withdraw
amount_entry = tk.Entry(win)
amount_entry.focus_set()

transaction_text_widget = tk.Text(win, height=10)
# The transaction text widget holds text of the accounts transactions
transaction_text_widget = tk.Text(win, height=10, width=48)

# The bank account object we will work with
account_obj = BankAccount()
# ---------- Button Handlers for Login Screen ----------


def clear_pin_entry(event):
    '''Function to clear the PIN number entry when the Clear / Cancel button is clicked.'''
    # Clear the pin number entry here
    account_pin_entry.delete(0, "end")


def handle_pin_button(event):
    '''Function to add the number of the button clicked to the PIN number entry via its associated variable.'''

    if win.focus_get() == account_number_entry:
        account_number_entry.insert("end", event)
    elif win.focus_get() == account_pin_entry:
コード例 #21
0
#             return 4
#         self.balance -= amount
#         return 0
#     def __str__(self):
#         return ("The balance for this account is ${0:,.2f}\n" +
#                "The minimum balance is ${1:,.0f}").format(
#                 self.balance, self.minimum_bal)

# import bankaccount # Requires the use of dot notation to call modules
import sys
sys.path.append('C:\\Users\\s728417\\Documents\\Python\\Python3\\Labs\\newDir')
print(sys.path)

from bankaccount import BankAccount, MinBalAcct  # Import from newDir

a = BankAccount('Guido van Rossum')  # Create an instance of Bankaccount
b = BankAccount('Monty Python')  # Create another instance
print('Number of accounts -', BankAccount.acct_cntr)  # print class variable
del a
print('Number of accounts -', BankAccount.acct_cntr)
c = MinBalAcct('Eric Idle', 5000, 1000)  # Create a minimum balance instance
print('Number of accounts -', BankAccount.acct_cntr)
print(c)
if c.withdraw(4500):
    print('Invalid withdrawal request')
print(c)
try:
    d = MinBalAcct('John Cleese', 500, 1000)
except ValueError as msg:
    print(type(msg.args))
    print("Account not established - ",
コード例 #22
0
    def setUp(self):
        # Create a test BankAccount object
        self.account = BankAccount()

        # Provide it with some property values        
        self.account.balance        = 1000.0
コード例 #23
0
 def __init__(self, username, email_address):
     self.name = username
     self.email = email_address
     self.account = BankAccount(int_rate=0.02, balance=0)
コード例 #24
0
def test_transactions(earned, spent, expected):
    my_account = BankAccount()
    my_account.add_cash(earned)
    my_account.spend_cash(spent)
    assert my_account.balance == expected
コード例 #25
0
##
#  This program tests the BankAccount class.
#
from bankaccount import BankAccount

harrysAccount = BankAccount(1000.0)
harrysAccount.deposit(500.0)  # Balance is now $1500
harrysAccount.withdraw(2000.0)  # Balance is now $1490 
harrysAccount.addInterest(1.0)  # Balance is now $1490 + 14.90
print("%.2f" % harrysAccount.getBalance())
print("Expected: 1504.90")   
コード例 #26
0
from bankaccount import BankAccount

a = BankAccount("Marko Knöbl", iban="AT1234")
b = BankAccount("Tom", "1111", 100.0)
c = BankAccount()

print(b.get_balance())

b.add_transaction("2019-03-15", 1000)
b.add_transaction("2019-04-01", -19.99)
b.add_transaction("2019-05-06", 2000)

print(b.transactions)

print(b.get_balance())

print(b.get_deposits())

print(b.get_transaction_descriptions())

for description in b.get_transaction_descriptions():
    print(description)
コード例 #27
0
balance_label = tk.Label(win, textvariable=balance_var)

brand_title_var = tk.StringVar()
brand_title_var.set("FedUni Banking")
brand_label = None

# The Entry widget to accept a numerical value to deposit or withdraw
amount_entry_var = tk.StringVar('')
amount_entry = tk.Entry(win, textvariable=amount_entry_var)

# The transaction text widget holds text of the accounts transactions

transaction_text_widget = tk.Text(win, height=10, width=48)
scrolbar = tk.Scrollbar(win)
# The bank account object we will work with
account = BankAccount()

# ---------- Button Handlers for Login Screen ----------


def clear_pin_entry(event):
    '''Function to clear the PIN number entry when the Clear / Cancel button is clicked.'''
    pin_number_var.set('')
    account_number_var.set('')
    # Clear the pin number entry here


def handle_pin_button(event):
    '''Function to add the number of the button clicked to the PIN number entry via its associated variable.'''
    data = pin_number_var.get()
    if len(data) < 4:
コード例 #28
0
def my_account():
    '''Returns a Wallet instance with a zero balance'''
    return BankAccount()
コード例 #29
0
def log_in(event):
    '''Function to log in to the banking system using a known account number and PIN.'''
    global account
    global pin_number_var
    global account_number_var

    read = event + '.txt'
    # Create the filename from the entered account number with '.txt' on the end
    # Try to open the account file for reading
    accept_loging = False
    try:
        with open(str(read),
                  'r') as account_file:  # Open the account file for reading

            account_number = account_file.readline(
            )[:-1]  # First line is account number

            account_pin = account_file.readline(
            )[:
              -1]  # Second line is PIN number, raise exceptionk if the PIN entered doesn't match account PIN read

            if account_pin != pin_number_var.get():
                raise ValueError("Pin doesnt match")
            else:
                accept_loging = True

            account_balance = float(account_file.readline(
            )[:-1])  # Read third and fourth lines (balance and interest rate)

            account_interest = float(account_file.readline()[:-1])
            transaction_list = []
            # Section to read account transactions from file - start an infinite 'do-while' loop here

            # Attempt to read a line from the account file, break if we've hit the end of the file. If we
            # read a line then it's the transaction type, so read the next line which will be the transaction amount.
            # and then create a tuple from both lines and add it to the account's transaction_list
            while True:
                _type = account_file.readline()[:-1]  # Attempt to read a line
                if not _type:  # If we failed, then exit
                    break
                _amount = float(account_file.readline()[:-1])

                transaction_list.append((_type.strip(), _amount))

            account.account_number = account_number
            account.account_pin = account_pin
            account.balance = account_balance
            account.account_interest = account_interest
            account.transaction_list = transaction_list
        # Close the file now we're finished with it (context manager is doing this for us)
    except ValueError:
        messagebox.showerror("Error", "Incorrect PIN")
        account = BankAccount()
        account.account_interest = .30
        account = account_number_var
        clear_pin_entry("event")
        account_number_entry.focus_force()
    except Exception:
        # Catch exception if we couldn't open the file or PIN entered did not match account PIN
        messagebox.showerror("Error", "file doesnt exists")
        account = BankAccount()
        clear_pin_entry("event")
        account_number_entry.focus_force()

        # Show error messagebox and & reset BankAccount object to default...

        #  ...also clear PIN entry and change focus to account number entry
    if accept_loging:
        remove_all_widgets()
        create_account_screen()
コード例 #30
0
def empty_account():
    """
    Vytvoří prázdný účet
    """
    return BankAccount()