112k views
1 vote
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.

User JPR
by
6.0k points

1 Answer

3 votes

Answer:

def statement(numbers):

deposits = []

withdrawals = []

for number in numbers:

if number > 0:

deposits.append(number)

if number < 0:

withdrawals.append(number)

return [sum(deposits), sum(withdrawals)]

Step-by-step explanation:

*The code is in Python.

Create a function called statement that takes numbers as a parameter

Inside the function, create two empty lists called deposits and withdrawals. Create a for loop that iterates through the numbers. Inside the loop, if a number is greater than 0, add it to the deposits. If a number is smaller than 0, add it to the withdrawals. When the loop is done, return the sum of the deposits and the sum of the withdrawals (use sum function to sum the numbers in the lists)

User Arul Suju
by
6.0k points