Quiz 6b Question 8————An Introduction to Interactive Programming in Python
2014-11-01 16:55
453 查看
wumpus. This one fast wumpus is a new mutation. Not surprisingly, being fast gives it an advantage, as it can better escape from predators. Each year, each wumpus has one offspring. (We'll ignore the more realistic niceties of sexual reproduction, like distinguishing
males and females.). There are no further mutations, so slow wumpuses beget slow wumpuses, and fast wumpuses beget fast wumpuses. Also, each year 40% of all slow wumpuses die each year, while only 30% of the fast wumpuses do.
So, at the beginning of year one there are 1000 slow wumpuses. Another 1000 slow wumpuses are born. But, 40% of these 2000 slow wumpuses die, leaving a total of 1200 at the end of year one. Meanwhile, in the
same year, we begin with 1 fast wumpus, 1 more is born, and 30% of these die, leaving 1.4. (We'll also allow fractional populations, for simplicity.)
Enter the first year in which the fast wumpuses outnumber the slow wumpuses. Remember that the table above shows the populations at the start of the year.
Question 8
We can use loops to simulate natural processes over time. Write a program that calculates the populations of two kinds of “wumpuses” over time. At the beginning of year 1, there are 1000 slow wumpuses and 1 fastwumpus. This one fast wumpus is a new mutation. Not surprisingly, being fast gives it an advantage, as it can better escape from predators. Each year, each wumpus has one offspring. (We'll ignore the more realistic niceties of sexual reproduction, like distinguishing
males and females.). There are no further mutations, so slow wumpuses beget slow wumpuses, and fast wumpuses beget fast wumpuses. Also, each year 40% of all slow wumpuses die each year, while only 30% of the fast wumpuses do.
So, at the beginning of year one there are 1000 slow wumpuses. Another 1000 slow wumpuses are born. But, 40% of these 2000 slow wumpuses die, leaving a total of 1200 at the end of year one. Meanwhile, in the
same year, we begin with 1 fast wumpus, 1 more is born, and 30% of these die, leaving 1.4. (We'll also allow fractional populations, for simplicity.)
Beginning of Year | Slow Wumpuses | Fast Wumpuses |
---|---|---|
1 | 1000 | 1 |
2 | 1200 | 1.4 |
3 | 1440 | 1.96 |
… | … | … |
slow_wumpu = 1000 fast_wumpu = 1 year = 1 while (slow_wumpu) > (fast_wumpu): slow_wumpu *= 1.2 fast_wumpu *= 1.4 year += 1 print year
相关文章推荐
- Quiz 6b Question 8————An Introduction to Interactive Programming in Python
- Quiz 6b Question 7————An Introduction to Interactive Programming in Python
- Quiz 6b Question 7————An Introduction to Interactive Programming in Python
- Quiz 6a Question 7————An Introduction to Interactive Programming in Python
- Quiz 6a Question 7————An Introduction to Interactive Programming in Python
- Mini-project # 4 - "Pong"___An Introduction to Interactive Programming in Python"RICE"
- Mini-project # 4 - "Pong"___An Introduction to Interactive Programming in Python"RICE"
- An Introduction to Interactive Programming in Python 第六课作业 Blackjack
- An Introduction to Interactive Programming in Python - Week zero
- Mini-project # 1 - Rock-paper-scissors-___An Introduction to Interactive Programming in Python"RICE"
- An Introduction to Interactive Programming in Python 第五课作业 memory
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 4 Pong
- [Coursera][Rice] An introduction to interactive Programming in Python Week 2 3
- Mini-project # 1 - Rock-paper-scissors-___An Introduction to Interactive Programming in Python"RICE"
- An Introduction to Interactive Programming in Python(week 7)
- 【coursera 学习笔记】An Introduction to Interactive Programming in Python--week0
- 【python】An Introduction to Interactive Programming in Python(week two)
- An Introduction to Interactive Programming in Python - Week one
- An Introduction to Interactive Programming in Python
- 【coursera 学习笔记】An Introduction to Interactive Programming in Python--week1