Help me in solving CANDYSTORE problem

My issue

runtime error

My code

# cook your dish here
T = int(input())
for i in range(T):
    X=int(input())
    Y=int(input())
    if Y>X:
        n=Y-X
        print(x+n*2)
    else:
        print(Y)
     

Learning course: Basic Math using Python
Problem Link: Candy Store Practice Problem in - CodeChef

So, Friend

The first problem is that in line number 8

The variable x should be of capital letter (python is case sensitive).

Now

input () takes a line as input

so, when you call

input() function its takes “3 1”

and you cannot convert this to integer.
so instead you can say

S = input()
X=int(S[0])
Y=int(S[2])

“3 2”
0 1 2 are indices. index 1 has space and cannot be converted to integer.

or if you are a bit advanced then you can say

[X, Y] = [int(i) for i in input().split(" ")]

this uses lit comprehension.
input().split(" ") gives [“3” , “2”] for the first line.

The first code is


# cook your dish here
T = int(input())
for i in range(T):
    S = input()
    X=int(S[0])
    Y=int(S[2])
    if Y>X:
        n=Y-X
        print(X+n*2)
    else:
        print(Y)

The second way is

#cook your dish here
T = int(input())
for i in range(T):
    [X, Y] = [int(i) for i in input().split(" ")]
    if Y > X:
        n = Y-X
        print(X+n*2)
    else:
        print(Y)

Hoping I could be of help. Have a great day.