我遇到了一个困境,因为 for i in range(x) 循环没有迭代。我的程序的目的是模拟狐狸和兔子在岛上的相互作用,并在每天之后打印出每种动物的种群。我知道方程式是正确的,我遇到的问题是我的循环只会在大范围内运行一次。
我的代码:
def run_simulation():
print()
RABBIT_BIRTH_RATE = 0.01
FOX_BIRTH_RATE = 0.005
INTERACT = 0.00001
SUCCESS = 0.01
x = 0
y = 1
FOXES = eval(input("Enter the initial number of foxes: "))
print()
RABBITS = eval(input("Enter the initial number of rabbit: "))
print()
DAYS = eval(input("Enter the number of days to run the simulation: "))
print()
print("Day\t","Rabbits\t","Foxes\t")
print(0,"\t",RABBITS,"\t","\t",FOXES,"\t")
for i in range(DAYS):
RABBITS_START = round((RABBIT_BIRTH_RATE * RABBITS) - (INTERACT * RABBITS * FOXES))
FOXES_START = round((INTERACT * SUCCESS * RABBITS * FOXES) - (FOX_BIRTH_RATE * FOXES))
y = y + x
print (y,"\t",(RABBITS_START+RABBITS),"\t","\t",(FOXES_START+FOXES),"\t")
run_simulation()
当以 500 只狐狸、10000 只兔子和 1200 天的示例运行时,我的输出将如下所示
Day Rabbits Foxes
0 10000 500
1 10050 498
第二条输出线重复剩余的 1199 次。任何帮助将不胜感激我无法弄清楚我做错了什么。