Posts

Showing posts with the label program

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

N is a prime number?

 Programe PYTHON checks if the number N is a prime number.  The algorithm consists of dividing the number N by all successive numbers 1, 2, 3,, sqrt (N) as long as the rest of the divisions are nonzero. The PYTHON program is: # Checks if the number N is a prime number N = int(input('Number is:')) # A = sqrt(N) 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 ('Number', N,  'prime') else:     print ('Number', N,  'is not prime') The results of the program 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/NumarPrim.py ================ Number is:887 Number 887 prime Python 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang...

First PYTHON program

The first program written in PYTHON gathers two numbers entered from the keyboard and displays the result. The program instructions are: #    First program a = input('First number:') b = input('Second number:') c = int(a) + int(b) print('Result c is:', c) IDLE Shell 3.10.2 afișază: 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/Primul program.py ============= First number:4 Second number:11 Result c is: 15 (March, 21, 2022)