# -*- coding: UTF-8 -*-
# Filename : test.py
import random
def get_counts(sequence):
counts={}
for x in sequence:
if x in counts:
counts[x] += 1
else:
counts[x] = 1
return counts
def sj():
a=random.randint(1,10000)
b=""
if a<462:
b=3
if a>461 and a<4371:
b=2
if a>4370:
b=1
return b
gdcs=[]
m=0
while m<1000000:
m=m+1
n=0
x=0
y=0
z=0
bd=0
gd=0
while n<1000:
n=n+1
s=sj()
if s<3:
bd=bd+1
if bd>29:
s=3
if s==3:
bd=0
bda=random.randint(1,20)
if bda==15:
gd=gd+1
x=x+1
if s==2:
y=y+1
if s==1:
z=z+1
gdcs.append(gd)
#print gdcs
print get_counts(gdcs)
代码