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:
Also Read:
- Hyphenate Letters in Python
- Earthquake in Python | Easy Calculation
- Striped Rectangle in Python
- Perpendicular Words in Python
- Free shipping in Python
- Raj has ordered two electronic items Python | Assignment Expert
- Team Points in Python
- Ticket selling in Cricket Stadium using Python | Assignment Expert
- Split the sentence in Python
- String Slicing in JavaScript
- First and Last Digits in Python | Assignment Expert
- List Indexing in Python
- Date Format in Python | Assignment Expert
- New Year Countdown in Python
- Add Two Polynomials in Python
- Sum of even numbers in Python | Assignment Expert
- Evens and Odds in Python
- A Game of Letters in Python
- Sum of non-primes in Python
- Smallest Missing Number in Python
- String Rotation in Python
- Secret Message in Python
- Word Mix in Python
- Single Digit Number in Python
- Shift Numbers in Python | Assignment Expert
- Weekend in Python
- Shift Numbers in Python | Assignment Expert
- Temperature Conversion in Python
- Special Characters in Python
- Sum of Prime Numbers in the Input in Python