Data Structure | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Data Structure

Hello please I need help really quick: I want to write a code in python as follows: A code with a function called '"Data" which acts as follows: When given a list of integers, returns 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.

5th Jan 2017, 10:20 PM
WILLIAMS FALODUN
WILLIAMS FALODUN - avatar
5 Answers
0
what?
5th Jan 2017, 10:24 PM
Maxim Kuzmin
Maxim Kuzmin - avatar
0
what is positive number?
5th Jan 2017, 10:24 PM
Maxim Kuzmin
Maxim Kuzmin - avatar
0
I would just run through the given list and test the data at each point with some if statements. if the item in the list >= 0 then increment the first item in the return list. For the negatives, test if the item is <0, and add it to the value of item 2 in your return list
5th Jan 2017, 10:26 PM
Ethan
0
def Data(z): x=c=0 for i in z: if i%2==0: c+=1 else: x+=i return([c,x])
5th Jan 2017, 10:35 PM
Maxim Kuzmin
Maxim Kuzmin - avatar
0
Maxim, adjust line 4 to read like: if i>=0: I think that should do it
5th Jan 2017, 10:43 PM
Ethan