Help me in solving BM08E problem

My issue

My code

# Update the '_' below to solve the problem

t = int(input())
for i in range(t):
    N, A = map(int, input().split())
    chef_chocolates = A
    chefina_chocolates = N - A
    diff = print(chefina_chocolates - chef_chocolates)
    print(diff)

Learning course: Python for problem solving - 1
Problem Link: CodeChef: Practical coding for everyone

@sneha_siri

The problem statement wants us to find the difference in magnitude or the absolute difference between the amount of chocolates.

In the code, you should have used abs function to get the difference in magnitude but you used print which caused an error.

You can refer to the following code for clarity.

# Update the '_' below to solve the problem

t = int(input())
for i in range(t):
    N, A = map(int, input().split())
    chef_chocolates = A
    chefina_chocolates = N - A
    diff = abs(chefina_chocolates - chef_chocolates)
    print(diff)
1 Like