Calculating 24 from 4 numbers (math Poker game) This is a game of math in Poker. Two people each have a pile of cards. They then each place 2 cards on the table at the same time. Every card is treated as a number. The players need to find a way to calculate 24 from the numbers. For example, you are given 3 5 4 8, and you can get 24 by (3+8-5) * 4, or 8*4-5-3. This code tries to solve this problem.

Can anyone help me to improve it?

comp()

def comp( nums,i,j,exps,op):
    nums0=[];
    for x in range(0,len(nums)):
        if not (x==i or x==j):
            nums0.append(nums[x])

    if(op=='+'):
        tmp = nums[i]+nums[j];
    elif(op=='*'):
        tmp = nums[i]*nums[j];
    elif(op=='-'):
        tmp = nums[i]-nums[j];
    elif(op=='/'):
        if(nums[j]&lt;0.0001 and nums[j]&gt;-0.0001 ):
            tmp=100000;
        else:
            tmp = nums[i]*1.0/nums[j];
    elif(op=='^'):
        return comp(nums,j,i,exps,'-');
    elif(op=='%'):
        return comp(nums,j,i,exps,'/');

    exps.append(str((nums[i],op,nums[j])));
    nums0.append(tmp);
    return nums0


cal()

def cal(nums, exps):
    if(len(nums)==1):
        return (nums[0]&gt;23.9999 and nums[0]&lt;24.0001);
    pairs = {};
    for i in range(0,len(nums)):
        for j in range(i+1,len(nums)):
            tmp_key= str((min(nums[i],nums[j]),max(nums[i],nums[j])));
            #print tmp_key
            if(pairs.has_key(tmp_key)):
                continue;
            #print 'put '+tmp_key
            pairs[tmp_key]=''
            for op in ('+','-','*','/','^','%'):
                nums0 = comp(nums,i,j,exps,op)
                if(cal(nums0,exps)):
                    print str(exps);
                exps.pop();




cal([3,9,10,7],[]);

cal([5,5,5,1],[]);

cal([10,9,4,1],[]);
A few pieces of feedback:


Semi-colons in Python aren't necessary, unless you're trying to issue two commands on one line like a=5;b=6.  I couldn't find a pep style guide that specifically bans them, but most Python code doesn't use them, as they are unnecessary.
You set temp_key to a str, but that is unnecessary.  I'm assuming you added that because you probably had it as a list before and got a "unhashable" error when trying to use a list as a dictionary key.  This is a perfect spot to use a tuple, and your code will work if you just remove the str (leaving the ()), because tuples are hashable and immutable.
Instead of relying on floating point accuracy, which isn't a problem given the magnitude of your examples, an alternative would be to use the fractions class and all your calculations would be exact.
Instead of recursively calling the comp function for your inverse negative and inverse divide, it'd probably be much simpler to just write tmp = nums[j]-nums[i].  I'd suggest it for the inverse divides too.