我正在尝试使用以下规则模拟绵羊场 . 从12个月大的绵羊开始 . 绵羊孩子间隔6个月 . 每次开玩笑,他们生下1个女性和1个男性孩子 . 这个女孩在12个月大的时候成熟并怀孕,在18个月分娩 . 我用1只绵羊模拟,结果很好,有2只绵羊它们不是 .

The desired result is ( after 36 months ) 农场动物总数 . 女性总数男性总数

class Sheep:

    def __init__(self,A,G):
        self.Age=int(A)
        self.Gender=bool(G)

    def Ageup(self):
        #The goat is female, and kids on 6 months cycle and gets pregnant at 12 months thus first kidding is at 18 months.
        if((self.Age > 17) and (not (self.Age % 6)) and self.Gender):
            self.Age = self.Age+6
            return True
        else:
            self.Age = self.Age+6 # if it not a pregnant goat , even then just increase the age and return false.
            return False


Farm=[]

# seed the farm with 2 female sheep of 13 months each to start with.
Farm.append(Sheep(18,1))
Farm.append(Sheep(18,1))

for months in range (0,18,6):
    for animal in range (0, len(Farm)):
        if(Farm[animal].Ageup()):
            Farm.append(Sheep(1,1)) # have a female kid
            Farm.append(Sheep(1,0)) # have a male kid
            print("Reproducing")
        else:
            print(" Eating Around")


male=0
female=0

for x in range (0,len(Farm)):
    if(Farm[x].Gender):
        female=female+1
    else:
        male=male+1

print (" The farm population is ", len(Farm))
print(" The number of females is : ", female)
print ("The number of males is :", male)