#!/usr/bin/env python
#編碼=utf-8
#作者qihigh
階級動物化:
__station1 =無
__station2 =無
def __init__(self):
自我。__station1 = 0
自我。__station2 = 0
def toStat(自身,事件):
if(event == 's1 '):
自我。__station1 = self。__station1+1
否則:
自我。__station2 = self。__station2+1
定義結果(自身):
回歸【自我。__station1,自己。__station2]
if __name__ == '__main__ ':
STR =[' ' --
#註:a01 - a09按a1 - a9處理。
dic = {}
對於範圍內的I(1.50):
#a0 =動物化()
exec("a"+`i`+" = AnimalStation()")
#dic['a0'] = a0
exec("dic['a"+`i`+"'] = a"+`i `)
對於字符串中的每壹行:
strs = eachLine.split(':')
動物,事件= strs[0],strs[2]
#dic['a28']。到(' s1 ')
exec("dic['"+animal+"']。toStat("+event+" ')")
print(" Animail \ t \ t station 1 \ t \ t station 2 ")
對於範圍內的I(1.50):
#打印dic['a0']。結果()
exec("result = dic['a"+`i`+"']。結果()")
print(" a "+` I `+ " \ t \ t "+` result[0]`+ " \ t \ t "+` result[1]`)
原理:利用python的動態特性。
實施結果:
動物站1站2
a1 0 0
a2 0 1
a3 0 0
a4 1 0
a5 0 0
a6 1 0
a7 1 0
a8 1
a9 0 0
a10 2 0
a11 2 0
a12 0 0
a13 0 0
a14 1 0
a15 0 0
a16 0 0
a17 0 0
a18 0 2
a19 1 0
a20 0 0
a21 0 0
a22 0 1
a23 0 0
a24 1 0
a25 0 0
a26 0 0
a27 0 0
a28 1 0
a29 0 0
a30 0 0
a31 1 1
a32 0 0
a33 0 1
a34 0 1
a35 0 1
a36 2 0
a37 2 0
a38 1 0
a39 0 1
a40 0 0
a41 1 0
a42 0 1
a43 0 0
a44 0 0
a45 0 0
a46 0 1
a47 0 0
a48 0 0
a49 0 1
妳想要的結果!!!給我就是。。。。。。。