###### Person模拟
#coding=utf-8

import random

persons = []

class Person():
def __init__(sepersonsf,age):
sepersonsf.age = age
sepersonsf.sexy = random.randint(0,1)

def grow_up():
for i in persons:
i.age += 1

for i in persons:
if 0<i.age<=20 and random.randint(0,100)<5:
persons.remove(i)
if 20<i.age<=40 and random.randint(0,100)<10:
persons.remove(i)
if 40<i.age<=60 and random.randint(0,100)<15:
persons.remove(i)
if i.age>60 and random.randint(0,100)<30:
persons.remove(i)

def born():
man = 0
woman = 0
for i in persons:
if 20<i.age<40:
if i.sexy:
man += 1
else:
woman += 1
for i in range(min(man, woman)):
if random.randint(0,100)<50:
persons.append(Person(0))

def show_msg():
man = 0
woman = 0
for i in persons:
if i.sexy:
man += 1
else:
woman += 1
print("总人数:%d 男性:%d 女性:%d" % (len(persons), man, woman))

def init():
for i in range(5000):
persons.append(Person(20))

init()
for i in range(100):
print("第%d年:" % (i+1))
show_msg()
born()
grow_up()

#### 模拟社会关系

2015-07-11 10:41:08

#### 设计模式练习（1）——简单工厂模式

2017-01-18 17:04:54

#### 顺便贴一下无聊的Java作业20151027

2015-10-27 23:50:09

#### java设计模式 实验一-简单工厂模式

2016-09-23 23:20:07

#### Java试验指导书

2017-12-03 22:25:07

#### Person p=new Person()的感悟

2014-07-07 08:45:01

#### JS如何创建对象及实现继承

2015-05-13 16:04:16

#### 深入理解利用new创建对象的执行过程以Person p=new Person(&quot;张三&quot;,20);为例

2015-02-06 19:02:46

#### Java小游戏源代码

2015年04月07日 662B 下载

#### 深入理解利用new创建对象的执行过程以Person p=new Person("张三",20);为例

2015-01-21 22:19:58

Person模拟