Posts

Showing posts with the label fuction

Count the positive elements in a list

PYTHON program is: # #    Count the positive elements, the zero elements, #    and the negative elements in a list. #    A function is constructed that returns three values. #        return a, b, c #        x, y, z = Count_list(List) is x,y,z=a,b,c # Count_positive = 0 Count_negative = 0 Count_zero = 0 List_elements_A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] List_elements_B = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] List_elements_C = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10] List_elements_D = [1, 2, 3, 0, 0, 0, 0, -1, -2, -3] def Count_list(List):     C_pos = 0     C_neg = 0     C_zer = 0     No_elem = len(List)     for i in range(No_elem):         if(List[i] > 0):             C_pos = C_pos +1         if(List[i] < 0):             C_neg = C_neg +1         if(List...