Search This Blog

Thursday, September 24, 2020

NPTEL Assignment Solution for Data structures and algorithm using Python

 

A positive integer m is a prime product if it can be written as p×q, where p and q are both primes. .

Write a Python function primeproduct(m) that takes an integer m as input and returns True if m is a prime product and False otherwise. (If m is not positive, your function should return False.)

 def primeproduct(x):
    z=0
    for i in range(2,x):
        if x % i == 0:
            k=x//i
            for j in range(2,k):
                if k % j == 0:
                    z=1
    if z==0:
        return True
    else:
        return False

No comments:

Post a Comment