ini:
[COMM]C0 = 0.1C1 = 0.25C2 = 0.35C3 = 0.45C4 = 0.55C5 = 0.56[POS_TAK]PT0 = 0.1PT1 = 1.1PT2 = 2.1PT3 = 3.1PT4 = 4.1PT5 = 5.1[BET_INFO]AMT = 100.23ODDS= 48.5
py:
#!/usr/bin/env python#coding=gbkimport ConfigParserimport syscomm = [] #commissionpt = [] #position takingamt = 0.0 #bet amtodds = 1.0 #oddsconfig = ConfigParser.ConfigParser()config.read("cfg.ini")#sections = config.sections()#print sections#o = config.options("POS_TAK")#print o#v = config.items("POS_TAK")#print vfor item in config.items("COMM"): comm.append( float( item[1] ) )for item in config.items("POS_TAK"): pt.append( float( item[1] ) )amt = float(config.items("BET_INFO")[0][1])odds = float(config.items("BET_INFO")[1][1])print '%10s:%s' % ('comm', comm)print '%10s:%s' % ('pt', pt)print '%10s:%-10.2f' % ('amt', amt)print '%10s:%-10.2f' % ('odd', odds)#################calc#####################c0 = pt[0] * comm[0] * amtc1 = pt[0] * (comm[1] + comm[2] + comm[3] + comm[4] + comm[5]) * amtc2 = (pt[0] + pt[1]) * (comm[2] + comm[3] + comm[4] + comm[5]) * amtc3 = (pt[0] + pt[1] + pt[2]) * (comm[3] + comm[4] + comm[5]) * amtc4 = (pt[0] + pt[1] + pt[2] + pt[3]) * (comm[4] + comm[5]) * amtc5 = (pt[0] + pt[1] + pt[2] + pt[3]+ pt[4]) * (comm[5]) * amt#pn0= pt[0]*amt -c0 -c1 #prize nopn1 = pt[0] * amt - c1pn2 = (pt[0] + pt[1]) * amt - c2pn3 = (pt[0] + pt[1] + pt[2]) * amt - c3pn4 = (pt[0] + pt[1] + pt[2] + pt[3]) * amt - c4pn5 = (pt[0] + pt[1] + pt[2] + pt[3] + pt[4]) * amt - c5#py0= pt[0]*amt -c0 -c1 #prize yespy1 = -(pt[0]) * amt * (odds - 1) - c1py2 = -(pt[0] + pt[1]) * amt * (odds - 1) - c2py3 = -(pt[0] + pt[1] + pt[2]) * amt * (odds - 1) - c3py4 = -(pt[0] + pt[1] + pt[2] + pt[3]) * amt * (odds - 1) - c4py5 = -(pt[0] + pt[1] + pt[2] + pt[3] + pt[4]) * amt * (odds - 1) - c5##############output##########################print '-' * 70print '%10s|%15s %15s %15s' % ('type', 'comm','no prize','prize yes')print '-' * 70print '%10s|%15.2f %15s %15s' % ('lv0', c0,'-','-')print '%10s|%15.2f %15.2f %15.2f' % ('lv1', c1,pn1,py1)print '%10s|%15.2f %15.2f %15.2f' % ('lv2', c2,pn2,py2)print '%10s|%15.2f %15.2f %15.2f' % ('lv3', c3,pn3,py3)print '%10s|%15.2f %15.2f %15.2f' % ('lv4', c4,pn4,py4)print '%10s|%15.2f %15.2f %15.2f' % ('lv5', c5,pn5,py5)print '-' * 70print 'Press ENTER to exit...'sys.stdin.read(1)#if __name__ == '__main__':# print 'hello 中國'