Expensive Number in Python

Problem Statement:

We need to find out whether a number is expensive or not. The condition to be an expensive number is that the number of digits of prime factorization of the number is greater than the total number of digits in the number itself.

Code to find Expensive Number in Python:

def prime_fact(n):
    result = []
    # while n doesn’t fully dissolve to 1
    while n!=1:
        # keep finding a lowest divisible number
        for i in range(2,n+1):
            if n%i==0:
                result.append(i)
                n = n//i
                # stopping once found so we don’t get any greater numbers
                break
    return result

input_num = int(input("Enter an INTEGER: "))

prime_factors = prime_fact(input_num)

if len(str(input_num)) == len(prime_factors):
    print('its an expensive number')
else:
    if len(prime_factors) > len(str(input_num)):
        print('cheap number')
    else:
        print('None')

Output:

Output to find Expensive Number in Python

Also Read:

Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you