Composite Numbers in the range
This Program name is Composite Numbers in the range. Write a Python program to Composite Numbers in the range, it has two test cases
The below link contains Composite Numbers in the range question, explanation and test cases
https://docs.google.com/document/d/17kmAlgcnB4bRnS354mEsgmWK-R38gTsx/edit?usp=sharing&ouid=107231566038157986423&rtpof=true&sd=true
We need exact output when the code was run
def IsPrime(n):
if n < 0:
raise ValueError('Negative value')
if n < 2:
return False
if n == 2:
return True
if n % 2 == 0:
return False
i = 3
while(i * i <= n):
if n % i == 0:
return False
i += 2
return True
def IsComposite(n):
if n < 0:
raise ValueError('Negative value')
if n == 1:
return False
return not IsPrime(n)
M = int(input())
N = int(input())
for i in range(M, N + 1):
if IsComposite(i):
print(i)
Comments
Leave a comment