Answer to Question #226150 in Python for GANESH

Question #226150

You are given two integers M, N as input. Write a program to print all the composite numbers present in the given range (including M and N)


1
Expert's answer
2021-08-17T12:55:57-0400
def IsNumberComposite(n):
    if n < 0:
        raise ValueError('The value must be positive')
    if n in [1, 2]:
        return False
    if n % 2 == 0:
        return True
    i = 3
    while(i * i <= n):
        if n % i == 0:
            return True
        i += 2
    return False

M = int(input())
N = int(input())

for i in range(M, N + 1):
    if IsNumberComposite(i):
        print(i, end=' ')
print()

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