Question #63703

Write a function called manipulate_data which will act as follows:

When given a list of integers, return a list, where the first element is the count of positives numbers and the second element is the sum of negative numbers.

NB: Treat 0 as positive.

Expert's answer

Answer on Question#63703 – Programming & Computer Science | Python


def manipulate_data(my_list):
    count_of_positive = 0
    sum_of_negative = 0
    for number in my_list:
        if number < 0:
            sum_of_negative += number
        else:
            count_of_positive += 1
    return [count_of_positive, sum_of_negative]


http://www.AssignmentExpert.com

LATEST TUTORIALS
APPROVED BY CLIENTS