 python vs Java ??

#1

Here is a very simple spoj question link http://www.spoj.com/problems/JULKA/

my python code is getting WA where as the same logic Java code is getting AC why what am i missing??

PYTHON3 : (This same code gets AC for python 2.7 with necessary adjustments to code syntax but gives WA for Python 3 Why?)

``````__author__ = "Achut"

for i in range(10):
a = int(input().strip())
b = int(input().strip())
k = int((a+b)/2)
print(k)
n = a - k
print(n)
``````

Java :

``````import java.util.*;
import java.math.*;

class JULKA {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
for (int t = 0; t < 10; t++) {
BigInteger A = new BigInteger(in.next());
BigInteger B = new BigInteger(in.next());
BigInteger N = A.subtract(K);
System.out.println(K.toString());
System.out.println(N.toString());
}
}
}``````

#2

n = a - res

Where did the variable res come from??? That should be k my boy !! And next time dont be in a hurry to post doubts on the forum. IT might be a simple mistake but will cost you a lot if you cannot find it on your own during a contest or an interview . Learn to debug on your own!

#3

Yeah it should be ‘k’ inspite of res .

#4

@achut i have submitted that problem in python 2.7 just now and i got AC with this code so just check it out.

t=10

while t:

``````n=input()

n=int(n)

k=input()

k=int(k)

n=n-k

n=n/2

print n+k

print n

t=t-1``````

#5

sorry thats k i initially used res for python for matching the java code i changed it

#6

yeah thats k i initially used res for python for matching the java code i changed it
i used the variables correct if it were a variable then it wont give WA it would give compilation error

#7

i used the variables correct in the original code if it were a variable then it wont give WA it would give compilation error

#8

If i put print(n+k) and print(n) instead and submit in python 3 i am getting WA even for your solution , why?

#9

@achut it is difficult to tell the exact problem.I myself did not submitted it in python 3.0 because someone has already mentioned it in comments that submission in python 3.0 caused him many WAs.so,check out is there any accepted submission in python3.0 or not

#10

@ma5termind thanks for you response