Python Forum

Full Version: convert to python 2.7
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hey guys! i wrote a program in python 3 and now want to convert the program to python 2.7. i was really unsucessfull at this. can anyone help me out please. below is my program.ignore indendation error.
Input Format :
The first line of input consist of number of test cases,
T.The first line of each test case consist of number of villains and player, N.
The second line of each test case consist of the N space separated strengths of Villains.
The third line of each test case consist of N space separated energy of players.
 if __name__ == '__main__':
    Testcases = int(input())
    for i in range(Testcases):
        N = int(input())
        v = list(map(int,input().rstrip().split()))
        p = list(map(int,input().rstrip().split()))

        v1= sorted(v)
        p1= sorted(p)



        win = 0

        for i in range(len(v)):
            if v1[i] < p1[i]:
                win +=1


        if win == len(v) :
            print("win")
        else:
            print("false")
Why would you want to do that? Python 3 is what you should be using, since 2 reached end of life at the beginning of the year.
Translating so little code it will be easiest to do by hand instead of using a translator tool. If I were translating this I would try to run the program and look at the error. Early errors (easy errors) will be syntax errors. Python 2.7 print doesn't use () and Python 2.7 input evaluates what you type so you don't have to use int(). However there are reasons that Python 3.x chose to make input work like Python 2.7 raw_input instead of input. That automatic conversion can cause a lot of problems. After changing print(a) to print a and input() to raw_input() I think the code will run.