General

Chat

python help

Can anyone help me on this python question?
I am lost on how to solve this
statement(LTransactions) - returns(totalWithdrawals,totalDeposits)
Write a function that takes as input a list of floating point numbers (or ints), LTransactions, representing deposits (positive numbers) and withdrawals (negative numbers). A two item list should be returned with entries totalWithdrawals, the sum of all withdrawals, and totalDeposits, the sum of all deposits.
The following result when run should return a statement like this
>>>statement([30.95, -15.67, 45.56, -55.00, 43.78])
[-70.67, 120.29]
the totalWithdrawals is the sum of all the negative transactions while the totalDeposits are the sum of all the positive ones

April 19, 2015

4 Comments • Newest first

iDrinkOJ

printf( " hello world " ) ;

Reply April 19, 2015
MarshMallows

Ok. So I don't want to give too much away, but here's some pseudo code.

First, define the function:

def myFunction(LIST):

#Define what you want to output
totalWithdrawals = 0
totalDeposits = 0

#Now you have to "loop" through the list
for integer in LIST:
---#Now, integer will be an element from the list, and what do you want to do?
---#Check if it's positive or negative right?
---#So to check if it's positive or negative use an if statement and compare it to this integer ___
---if INTEGER IS LESS THAN ___:
---#add to totalWithdrawals
---if INTEGER IS MORE THAN ___:
---#add to totalDeposits

#Now, after you exit the for loop, you must return!
return [totalWidthdrawals, totalDeposits]

Edit: Ok, I basically gave most of the code away now that I look back at it

Edit 2: If this were stackoverflow, I would be willing to bet you would receive a crap ton of downvotes. It's generally better to show how much work you've already done, rather than just asking for an answer - which is what I think you've been doing looking at your past threads.

Reply April 19, 2015 - edited
Sammi

live rats are better than frozen rats

Reply April 19, 2015 - edited
MistFTW

Have you written any code yet?

Reply April 19, 2015 - edited