Source

wd_pys60 / wd_24.py

A,B,C,D=[float(i) for i in raw_input("ABCD:").split()]

def jia(former,later):
    return former+later

def jian(former,later):
    return former-later

def cheng(former,later):
    return former*later

def chu(former,later):
    return former/later

methodDic={jia:"+",jian:"-",cheng:"*",chu:"/"}


from wd_24_source import *

methods=eval("["+methodSource.replace("'","").replace("\n",",")+"]")

nums=eval("["+numSource.replace("'","").replace("\n",",")+"]")
quit=0
for a in nums:
    for b in methods:
        res=a[0]
        for i in range(1,4):
            #print res,methodDic[b[i-1]],a[i],"=",
            res=b[i-1](res,a[i])
        #print res
        if res==24.0:
            for i in range(3):
                print a[i],methodDic[b[i]],
            print a[-1],"=24"
            quit=1
        if quit:
            break
    if quit:
        break