Question 7

Convert the following English description into code.

  1. Initialize n to
    be 1000. Initialize numbers to
    be a list of numbers from 2 to n, but not including n.
  2. With results starting
    as the empty list, repeat the following as long as numbers contains
    any numbers.

    • Add the first number in numbers to
      the end of results.
    • Remove every number in numbers that
      is evenly divisible by (has no remainder when divided by) the number that you had just added to results.

How long is results?

To test your code, when n is
instead 100, the length of results is
25.

代码:

lis = list(range(2,1000))
print lis[0]
res =[]
print len(res)
res.append(lis[0])
while len(lis)>1:
for i in lis:
if i % res[-1]==0:
lis.remove(i)
res.append(lis[0])
print lis print len(res)

Quiz 6b Question 7————An Introduction to Interactive Programming in Python的更多相关文章

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

     Question 8 We can use loops to simulate natural processes over time. Write a program that calcula ...

  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. for循环例子1、2、3

    /* Name:for循环例子1.2.3 Copyright: By.不懂网络 Author: Yangbin Date:2014年2月12日 02:12:41 Description:该代码用来熟悉 ...

  2. MySQL 用户登录与操作执行

    一个用户可以不登录进Mysql 数据库,由两方面的因数决定 1.你是谁:也就是mysql 数据库中记录的用户名和密码,在SQL Server数据库,中只要求说明你是谁就可以登录了,可是mysql 不是 ...

  3. linux下如何查看系统和内核版本

        1. 查看内核版本命令: 1) [root@q1test01 ~]# cat /proc/version Linux version 2.6.9-22.ELsmp (bhcompile@cro ...

  4. Bootstrap禁用响应式布局

    在Bootstrap中极其重要的一个技术内容便是响应式布局了,一次编码针对不同设备终端的强大能力使得响应式技术愈发流行. 不过正所谓"萝卜青菜各有所爱",如果你想要使用Bootst ...

  5. HDU 4622 Reincarnation(后缀自动机)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4622 [题目大意] 给出一个长度不超过2000的字符串,有不超过10000个询问,问[L,R]子串 ...

  6. POJ 1226 Substrings(后缀数组+二分答案)

    [题目链接] http://poj.org/problem?id=1226 [题目大意] 求在每个给出字符串中出现的最长子串的长度,字符串在出现的时候可以是倒置的. [题解] 我们将每个字符串倒置,用 ...

  7. oracle rac ha

    ha,仅只是在操作系统层面进行数据库的监控和管理,一般只针对单实例数据库使用.优点是管理方便,应用开发方便(方便了开发商):工程投入较小.缺点是,具有所有单实例数据库的缺点:如:容错能力差,续航能力差 ...

  8. Seoer,牵起用户与搜索引擎双手的魔术师

    SEOer:牵起用户与搜索引擎双手的魔术师 我想这是你的第一个疑问. SEO不是针对搜索引擎的技术吗?与用户有什么样的关联呢?又为何称他作魔术师呢?假设你有这些疑问.这篇文章就值得你阅读.SEO.搜索 ...

  9. EBS OAF 开发中的OAMessageRadioGroup控件

    EBS OAF 开发中的OAMessageRadioGroup控件 (版权声明,本人原创或者翻译的文章如需转载,如转载用于个人学习,请注明出处:否则请与本人联系,违者必究) 简单介绍 RadioGro ...

  10. IOS obj-c、c、c++混编

    今天发现这个问题,上网找了一下资料,发现原来如下: .m 文件可以混合c 和 objective-c 代码 .mm  文件可以混合 c c++ objective-c 代码 .c  .cpp  不能混 ...