Exercise 15 

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

# Ask to type a value of the integer n
n = int(input("Type a value of the integer n : "))

# use an auxiliary variable j that will count the number of divisors of n
j = 0
for i in range(1, n+1):
if(n%i == 0):
j = j + 1
if( j == 2):
print("The integer ", n , " is a prim number")
else:
print("The integer ", n , " is not a prim number")
Younes Derfoufi
One thought on “Solution Exercise 15 *”

Leave a Reply