## Sunday, August 30, 2020

Solution Exercise 63: algorithm python to test primality of an integer

#### Exercise 63

Write a program in Python language that asks the user to enter an integer n and display it if this number is prime or not.

#### Solution

``````# Enter value of the integer n
n = int(input("Enter value of the integer n : "))

# we must use an auxiliary variable j that will count the number of divisors of n
# initialize value of j
j = 0
for i in range(1, n+1):
# we test if i is a divisor of n, then we increment j
if(n%i == 0):
j = j + 1

# The integer n is prim number if and only if j is equal to 2
if( j == 2):
print("The integer ", n , " is a prim number")
else:
print("The integer ", n , " is not a prim number")
``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 