Answer to Question #256402 in Python for rasi

Question #256402

Given an integer num (1<n<100). Find a minimal divisor that is not equal to the given number and the sum is equal to the given number. Input: 9

Output: 18


1
Expert's answer
2021-10-25T09:39:44-0400






# Function to get sum of digits 
def getSumDigits(number):
    sumResult = 0
    for digit in str(number): 
      sumResult += int(digit)      
    return sumResult




def getMinimalDivisor(number):
    for i in range(number+1, number*1000000):
        if i%number == 0 and getSumDigits(i)==number:
            return i
    return -1


   
number = int(input("Enter a number: "))
minimalDivisor=getMinimalDivisor(number)
if minimalDivisor==-1:
    print ("No minimal divisor for number {}".format(number))
else:
    print ("The minimal divisor for number {} is {}".format(number,minimalDivisor ))

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