Can anyone tell me what is wrong with my code?

Input

An input contains 2 integers A and B .

Output

Print a wrong answer of A - B . Your answer must be a positive integer containing the same number of digits as the correct answer, and exactly one digit must differ from the correct answer. Leading zeros are not allowed. If there are multiple answers satisfying the above conditions, anyone will do.

Blockquote
try:

a,b = map(int,input().split())

n = a-b

i = n

count = 0

while i > 10:

    if i%10 == 0:

        i = i/10

        count+=1

    else:

        break

r = n-(10**count)

print(r)

except EOFError:

pass

have you tried same testcases? a=11 and b=1 for example?

1 Like

@rowdyninja try a = 13 and b = 3, your code print 10 but the answer should be different.

P.S: Always share the link to the question if possible.

Problem link: CIELAB Problem - CodeChef
Please provide this whenever you ask for help in a problem.

This is a logical approach. But, it fails for all test cases where the difference comes out to be a power of 10 like 10, 100, or 1000. In the else, if you check for it being a power and then make your program add instead of subtracting, it will work.

I used a simpler approach where I only deal with changing the ones digit: CodeChef: Practical coding for everyone

@carre thanks! I’ll try to correct it

thanks @rishup_nitdgp and here’s the link

@tanmay_garg thank you!