Answer to Question #256415 in Python for rasi

Question #256415

 14. For the given number ‘n’ (0 <n<= 100), little johnny wants to find out the minimum positive integer X divisible by ‘n’, where the sum of digits of X is equal to ‘n’ and X is not equal to 'n'. 

Note: If such an 'X number does not exist, then the output should be - 1.


1
Expert's answer
2021-10-28T06:59:04-0400
n = int(input("Enter n: "))
i = 1
flag = 0
while i < 10000000:
    if i == n:
        i = i + 1
        continue
    if i % n == 0:
        x = [int(a) for a in str(i)]
        b = sum(x)
        if b == n:
            print("Value is:", i)
            flag = 1
            break
    i = i + 1
if flag == 0:
    print(-1)

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