Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Python Expert

Bank transfer

What  if we  have  two  values,  representing bank  accounts, and  need  to transfer an  amount of money  amt between them?  Consider that a bank account is shown as a list of values,  such as ['Alyssa', 8300343.03, 0.05], defining that 'Alyssa' has a bank balance  of $8,300,343.03, and has to give a 5-cent fee for every  bank transaction. We may  give  this function as follows. It transfers the amount from  one balance  to the other,  and  deduct the transaction fee from  each account.

def transfer(a1, a2, amt):

a1[1] = a1[1] - amt - a1[2]

a2[1] = a2[1] + amt - a2[2]

To understand what  it's doing,  you really have to read  the code at a detailed layer.  Furthermore, it's simple to get the variable names  and subscripts wrong.

 

Here's another version that  abstracts away  the common idea of a deposit (which  can be positive or negative) into a function, and uses it twice:

 

def transfer(a1, a2, amt): deposit(a1, -amt) deposit(a2, amt)

def deposit(a, amt):

a[1] = a[1] + amt - a[2]

 

Now,  transfer looks pretty simple, but deposit can  still use some work.  In particular, the need of numeric indices  to get the components out of the bank  account de?nition is a bit cryptic  (and easy to get wrong).10

 

def deposit(a, amt):

(name, balance, fee) = a

a[1] = balance + amt - fee

 

Here,  we've used  a destructuring assignment statement to give names  to the components of the account. Unfortunately, when  we want  to modify  a component of the list showing the account, we have  to index  it explicitly.   Shown  that  we have  to use explicit  indices,  this  mechanism in which  we name  them  might  be better.

 

acctName = 0 acctBalance = 1 acctFee = 2

def deposit(a, amt):

a[acctBalance] = a[acctBalance] + amt - a[acctFee]

 

Strive, in your  programming, to make  your  code as easy, simple, clear and  direct  as possible.  Rarely,  the clear  and  simple approach will be too inef?cient, and  you'll have  to work on  something more  hard. In such type, you should still initiate with  something simple and  clear,  and  in the end, you may use it as documentation

 

Python, Programming

  • Category:- Python
  • Reference No.:- M9506010

Have any Question?


Related Questions in Python

Question write a python program with a graphical user

Question: Write a python program with a graphical user interface that will allow a user to create a custom pizza which they wish to order. At minimum, the user should be able to choose the size of the pizza, the type of ...

Learning outcomes lo3 - research develop and document a

Learning Outcomes LO3 - Research, develop, and document a basic security policy, and analyse, record, and resolve all security incidents LO4 - Identify and assess the threats to, and vulnerabilities of networks Assessmen ...

Lab assignment -background - we have discussed in detail

Lab Assignment - Background - We have discussed, in detail, the function of Stacks and Queues and how they are specifically implemented in Python. To get a better understanding of the utility of these data structures, we ...

Question why is software configuration management

Question : Why is software configuration management considered an umbrella activity in software engineering? Please include examples and supporting discussion. The response must be typed, single spaced, must be in times ...

A software company sells a package that retails for 99

A software company sells a package that retails for $99. Quantity discounts are given according to the following table: Quantity Discount 10 - 19 20% 20 - 49 30% 50 - 99 40% 100 or more 50% Write a program using python t ...

The second task in this assignment is to create a python

The second task in this assignment is to create a Python program called pancakes.py that will determine the final order of a stack of pancakes after a series of flips.(PYTHON 3) Problem Task In this problem, your input w ...

Environment setupthe first mini project will be based on

Environment Setup The first mini project will be based on Ladder Logic programming. We will be using Schneider Electric's IDE called SoMachine Basic to do the programming. The latest ver- sion of SoMachine Basic for Wind ...

Architecture and system integrationcase study queensland

Architecture and System Integration Case Study: Queensland Health - eHealth Investment Strategy After evaluating various platforms, Queensland Health finally decided to adopt a Service Oriented Architecture (SOA) for its ...

Show times in tmus and seconds1 an associate grasps an oven

Show times in TMUs and seconds. 1. An associate grasps an oven door within reach and pulls it open 18 inches with the left hand (he does not relinquish control of the door). With a pan in the right hand, he carefully pos ...

Homework -this homework will have both a short written and

Homework - This homework will have, both a short written and coding assignment. The problems that are supposed to be written are clearly marked. 1) (Written) Make heuristics Describe two heuristics for the slide problem ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As