我必須找到捕食者對獵物示例的新值。捕食者vs獵物蟒蛇程序
這是我當前的代碼
# Prompting user for all the inputs
A = float(input('Rate at which prey birth exceeds natural death'))
B = float(input('Rate of predation'))
C = float(input('Rate at which predator deaths exceed births without food'))
D = float(input('predator increase in the presence of food'))
popPrey = int(input('initial prey population'))
popPred = int(input('initial predator population'))
period = int(input('number of periods'))
# Finding new values of predator and prey populations
for i in range(period):
popPrey, popPred = popPrey*(1+A-B*popPred), popPred*(1-C+D*popPrey)
print "There are {%.0f} predators and {%.0f} prey after time period {%f}" %(popPred,popPrey,period)
我現在的問題是,我對我的回答期數總是5.我需要它像1,2,3,4,5。目前,它看起來像 這裏{20}天敵和{700}獵物一段時間後{5.000000}
有{20}天敵和{489}獵物後時間段{5.000000}
有{ 20}天敵和{341}獵物時間段{之後5.000000}
有{20}天敵和時間段{5.000000}
有{20}天敵和{166}獵物後{238}獵物經過一段時間{5.000000}
任何想法如何解決?
爲什麼會產生輸出變化?您在代碼中的哪個位置嘗試更改它? – Bach