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 fast
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.)

Beginning of Year Slow Wumpuses Fast Wumpuses
1 1000 1
2 1200 1.4
3 1440 1.96

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.

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的更多相关文章

  1. Quiz 6b Question 7————An Introduction to Interactive Programming in Python

     Question 7 Convert the following English description into code. Initialize n to be 1000. Initiali ...

  2. Quiz 6a Question 7————An Introduction to Interactive Programming in Python

     First, complete the following class definition: class BankAccount: def __init__(self, initial_bal ...

  3. An Introduction to Interactive Programming in Python

    这是在coursera上面的一门学习pyhton的基础课程,由RICE的四位老师主讲.生动有趣,一共是9周的课程,每一周都会有一个小游戏,经历一遍,对编程会产生很大的兴趣. 所有的程序全部在老师开发的 ...

  4. An Introduction to Interactive Programming in Python (Part 1) -- Week 2_3 练习

    Mini-project description - Rock-paper-scissors-lizard-Spock Rock-paper-scissors is a hand game that ...

  5. Mini-project # 1 - Rock-paper-scissors-___An Introduction to Interactive Programming in Python"RICE"

    Mini-project description - Rock-paper-scissors-lizard-Spock Rock-paper-scissors is a hand game that ...

  6. 【python】An Introduction to Interactive Programming in Python(week two)

    This is a note for https://class.coursera.org/interactivepython-005 In week two, I have learned: 1.e ...

  7. An Introduction to Interactive Programming in Python (Part 1) -- Week 2_2 练习

    #Practice Exercises for Logic and Conditionals # Solve each of the practice exercises below. # 1.Wri ...

  8. An Introduction to Interactive Programming in Python (Part 1) -- Week 2_1 练习

    # Practice Exercises for Functions # Solve each of the practice exercises below. # 1.Write a Python ...

  9. Mini-project # 4 - "Pong"___An Introduction to Interactive Programming in Python"RICE"

    Mini-project #4 - "Pong" In this project, we will build a version of Pong, one of the firs ...

随机推荐

  1. Linux 查看支持的语言,日期,时间,计算器

    1.查看系统目前支持的语言 echo %LANG 2.查看日历 cal 3.查看日期时间 date 4.计算器 bc

  2. Umbraco隐藏属性

    Umbraco默认的Url地址,是根据Node路径来默认显示的,因此使用中文的话比较尴尬. 网上有传的方法,是修改源码,来实现Url的重写. 但实际大可不必如此麻烦,只需要增加两个类型为Textstr ...

  3. Zepto Api参考

    zepto API参考 简介 Zepto是一个轻量级的针对现代高级浏览器的JavaScript库, 它与jquery有着类似的api. 如果你会用jquery,那么你也会用zepto. 设计目的 ze ...

  4. PE头的应用---插入代码到EXE或DLL文件中

    三.代码实现(DELPHI版本),采用第三种方式实现代码插入. 1. 定义两个类,一个用来实现在内存中建立输入表:一个用来实现对PE头的代码插入. DelphiCode: const MAX_SECT ...

  5. PHP批量下载方法

      PHP批量下载方法 界面: $.get(“< ?php echo url::base(true);?>inventory/report/buildCsv”, //后台路径 {‘para ...

  6. 安卓中onBackPressed ()方法的使用

    一.onBackPressed()方法的解释 这个方法放在 void android.app.Activity.onBackPressed() 在安卓API中它是这样解释的: public void ...

  7. Android应用开发基础篇(12)-----Socket通信

    链接地址:http://www.cnblogs.com/lknlfy/archive/2012/03/03/2378669.html 一.概述 网络通信无论在手机还是其他设备上都应用得非常广泛,因此掌 ...

  8. BZOJ 2314: 士兵的放置( 树形dp )

    树形dp... dp(x, 0)表示结点x不放士兵, 由父亲控制: dp(x, 1)表示结点x不放士兵, 由儿子控制: dp(x, 2)表示结点x放士兵. ---------------------- ...

  9. HTML+CSS笔记 CSS入门续集

    继承 CSS的某些样式是具有继承性的,那么什么是继承呢?继承是一种规则,它允许样式不仅应用于某个特定html标签元素,而且应用于其后代(标签). 语法: p{color:red;} <p> ...

  10. 10-C语言函数

    目录: 一.函数 二.return与exit关键字 三.递归与递推 回到顶部 一.函数 1 函数由函数名.返回值.形参.函数体组成. 函数的使用分三个步骤:声明.定义.调用 2 语法格式: 返回值类型 ...