nums = [ [2018 + j*10] + 4*[0] for j in range(11) ] # 0 the numbers represent year # 1 out of fertile window people # 2 fertile population # 3 children # 4 newborns for i, j in enumerate(nums): if i == 0: nums[0] = [2018, 0, 7, 0, 0] print(nums[i]) continue # the if takes care of people going out of the fertility window if i > 2: # fertile people are previous + people who became fertile 30 years ago nums[i][1] = nums[i-1][1] + (nums[i-3][2] - nums[i-4][2]) # the fertile people are previous - those who became fertile 30 years ago nums[i][2] = nums[i-1][2] - (nums[i-3][2] - nums[i-4][2]) # fertile people are fertile + previous children nums[i][2] = nums[i-1][2] + nums[i-1][3] # children are previous newborns nums[i][3] = nums[i-1][4] # newborns are 140% of the fertile people nums[i][4] = round(nums[i-1][2] * 1.4) print(nums[i])
Standard input is empty
[2018, 0, 7, 0, 0] [2028, 0, 7, 0, 10.0] [2038, 0, 7, 10.0, 10.0] [2048, 7, 17.0, 10.0, 10.0] [2058, 7, 27.0, 10.0, 24.0] [2068, 7, 37.0, 24.0, 38.0] [2078, 17.0, 61.0, 38.0, 52.0] [2088, 27.0, 99.0, 52.0, 85.0] [2098, 37.0, 151.0, 85.0, 139.0] [2108, 61.0, 236.0, 139.0, 211.0] [2118, 99.0, 375.0, 211.0, 330.0]