0

Write a python function to return the decimal value of 1)no. of positive no.2)no. of neg. no. to the no. Of elements in array

Arr=[1,2,-4,-6,-2,-1] Output: 0.333333 0.666666 Process: No. Of positive elements in array =2 No. Of negative elements in array =4 Total no.of elements in array =6 So, 2/6=0.333333 4/6=0.666666

17th Apr 2020, 5:03 AM
bhaskar bhowick
bhaskar bhowick - avatar
2 Answers
+ 1
Loop over the array and count the number of positive numbers in the array using n > 0 edit: whoops was checking for even b4 lol You may also need to count the number of zeros in the array using n == 0 or add && n != 0 to previous check. Then you can get the amount of negative numbers in the array by adding the count of positive numbers and zeros together and then subtract that from the array length array length - (npos + nzeros)
17th Apr 2020, 5:23 AM
ChaoticDawg
ChaoticDawg - avatar