Question

5.34 Write a function statement() that takes as input a list of floating-point numbers, with positive...

5.34 Write a function statement() that takes as input a list of floating-point numbers, with positive numbers representing deposits to and negative numbers representing withdrawals from a bank account. Your function should return a list of two floating-point numbers; the first will be the sum of the deposits, and the second (a negative number) will be the sum of the withdrawals. >>> statement([30.95, -15.67, 45.56, -55.00, 43.78]) [120.29, -70.67]

Homework Answers

Answer #1

ANSWER:

def statement(numList):

deposits = 0

Withdrawals = 0

outcome= []

for number in numList:

if number<0:

withdrawals += numList

else

deposits += numList

outcome.append(withdrawals)

outcome.append(deposits)

return outcome

Explanation:

I have defined a function called as statement() that has a parameter numList. Inside the function, I have created two empty lists of floating point numbers, with positive numbers representing deposits and negative numbers representing withdrawals from a bank account.

Now I have created a for loop that iterates through the numList. Inside the loop, if a number is smaller than zero, add it to the withdrawals. If a number is greater than zero, add it to the deposits. When the loop is done, the fuction returns a list of two floating point numbers. The first will be the sum of the deposits, and the second (a negative number) will be the sum of the withdrawals.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In R- Studio : Write a function that takes as an input a positive integer and...
In R- Studio : Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Write a recursive function, do not use any of the loop commands in your code.
Write a Scheme function that takes a simple list of numbers as a parameter and returns...
Write a Scheme function that takes a simple list of numbers as a parameter and returns a list with the largest and smallest numbers in the input list.
Write a function named “highestScore” that takes an array of floating point scores and its size...
Write a function named “highestScore” that takes an array of floating point scores and its size as parameters and return the highest of these scores. The function prototype: float highestScore(float scores[], int size);
Write a PYTHON program that takes the radius of a sphere (a floating-point number) as input...
Write a PYTHON program that takes the radius of a sphere (a floating-point number) as input and then outputs the sphere’s surface area. The Surface Area of a Sphere is Surface Area = 4πr² Surface Area = 4 * PI * radius * radius
Write a Python function evaluateFunction() that takes one floating point number x as its argument and...
Write a Python function evaluateFunction() that takes one floating point number x as its argument and returns 3√(log⁡|x| )+3(x^3) The math module has a square root function and a logarithm function
Write a function called sum_half that takes as input a square matrix A and computes the...
Write a function called sum_half that takes as input a square matrix A and computes the sum of its elements that are in the upper right triangular part of A, that is, elements in the diagonal and elements that are to the right of it. For example, if the input is [1 2 3; 4 5 6; 7 8 9], then the function would return 26. (That is, 1+2+3+5+6+9) Note, the function triu is not allowed. Please write as you...
A sequence is a list of numbers that are calculated based on a certain rule. For...
A sequence is a list of numbers that are calculated based on a certain rule. For instance, the progression described by the rule An = 2 ∗ n results in the numbers: 0 2 4 6 8 10 ··· 2 ∗ n. The sum of this sequence can be calculated as Sn = 0+2+4+6+8+10+···+2 ∗ n. Write a function that takes as input the number n and calculates the sum of the sequence up to the nth term (inclusive) for...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function...
TO BE DONE IN PYTHON: Write a function `lowest_integer()` which takes 2 input arguments: 1)a function `g` representing an increasing function g(x) 2) a number `gmin`, and returns an integer `nmin` such that nmin>0 is the smallest integer that satisfies g(nmin)>gmin. test: def g(n): return 2*n print(lowest_integer(g, 10)) Output: 6
Write a function called TaylorSin.m that takes as input an array x, and positive integer N,...
Write a function called TaylorSin.m that takes as input an array x, and positive integer N, and returns the Nth Taylor polynomial approximation of sin(x), centered at a = 0. The first line of your code should read function s = TaylorSin(x,N) HINT: in computing k!, use kfact = k*(k-1)*kfact since you are counting by 2
[Python] Write a function named "total_population" that takes a string then a list as parameters where...
[Python] Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a list containing 3 strings as elements representing the CountryCode, CityName, and Region in this order. Return the total population of all cities in the list. Note that the city must match the country, name, and...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT