Posts

Showing posts with the label language

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...

Generates M prime numbers

Programe is: # Generates M prime numbers, M > 1 M = int(input('Number of prime numbers  are:')) print ('Prime numbers list is:') print (1,  '  ') print (2,  '  ') print (3,  '  ') # MM = M  K = 1 N = 3 while K <= M:     A = N**0.5     B = int(A)     C = False     D = 2     while (C == False) and (D <= B):         if(N % D) == 0:             C = True         D = D + 1     if (C == False):         print ( N,  '  ')     N = N + 2     K = K + 1 print ('The list was successfully printed') Results are:  Python 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin Type "help", "copyright", "credits" or "license()" for more information. ========= RESTART: /Users/ionivan/Documents/GenerareListaNumerePrime.py ======== Number...

PYTHON Language Programming

PYTHON language programming is: - flexible, - portable, - easy, - free, - accessible,  - intuitive, - versatile, - universal,  - convenient, - ordinary,  - common. PYTHON programming language has taken over the best of all the programming languages before it. It is simple, efficient, dense and attractive. The input() statement is used to enter the data. The print() instruction is used to present the results. Variable names are constructed the same as all other programming languages: - the first character is required a letter, - the other characters are letters, numbers or underscores, - uppercase letters differ from lowercase letters, - any words other than the reserved words of the PYTHON language. - the length of the name does not exceed 31 characters. The string is preceded and followed by quotation marks. The string is preceded and followed by an apostrophe. Correct variable names: a i j temp Triangle surface_cercle  volume_cube Name_P...