Answer to Question #224928 in Python for Hari nadh babu

Question #224928

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

1
Expert's answer
2021-08-10T06:49:09-0400
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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS