Q1)Write a program that takes a number from the user and prints whether it is prime or not prime.
SOLN-1 PYTH:
n = 1319
d = 2
while d <= n//2:
if n%d == 0:
print('not a prime')
d+=1
else:
print(d)
print('prime')
- In the name of
'n'variable is used to store the value which is'1319', and in another variable name'd'to store the value'2'. - Here,i am used while loop to check the condition d<=n//2 which is
d=2->. - If
2<=1319then it's get into the loop and check another condition which i given inside the loop is another 'if'. - To check
1319%2 == 0if this condition satisfied then i used toprint('not a prime).
SOLN-2 :
n = 1319
d=2
while d<n:
if n%d ==0:
print('not a prime')
break
d+=1
else:
print(n)
print('prime')
SOLN-3 :
p=7
d=2
if d%p == 0:
print('not a prime')
d+=1
else:
print(d)
print('prime')
Top comments (0)