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. MySQL的InnoDB和MyISAM比较

    InnoDB 1)虽然不支持用户创建聚族索引,但InnoDB会对主键建立聚簇索引.如果你不指定主键,InnoDB会用一个具有唯一且非空值的索引来代替.如果不存在这样的索引,InnoDB会定义一个隐藏的 ...

  2. Http record java

    http://httpunit.sourceforge.net/doc/servletunit-intro.html https://code.google.com/p/http-impersonat ...

  3. php socket 超时设置

    1.php创建socket的方法和设置超时的方法,贴出来分享一下 //如果$waitAckSec=0,则返回成功发送的字节�? //如果$waitAckSec大于0,则返回发送后接收到得内容 //任何 ...

  4. Advanced Replication同步复制实验(基于Trigger&基于Materialized View)

    1. 高级复制和流复制介绍 1.1 高级复制(Advanced Replication) 高级复制也称为对称复制,分为多主体站点复制(Multiple Master Rplication).物化视图站 ...

  5. cocos2dx 坐标和锚点

    cocos2dx中使用opengl坐标系,左下角为坐标原点,在大部分情况下,都是使用这种坐标系的. 当我们创建了一个渲染对象到窗口后,那么这个对象本身也是也是有自己的坐标系的,这种坐标系是节点自己的坐 ...

  6. Element DOM Tree jQuery plugin – Firebug like functionality | RockingCode

    Element DOM Tree jQuery plugin – Firebug like functionality | RockingCode Element DOM Tree jQuery pl ...

  7. [置顶] 【cocos2d-x入门实战】微信飞机大战之二:别急,先处理好CCScene和CCLayer的关系

    转载请表明地址:http://blog.csdn.net/jackystudio/article/details/11713197 在整个游戏开始之前,我们先看一下HelloWorld示例中CCSce ...

  8. Bzoj2034 2009国家集训队试题 最大收益 贪心+各种优化+二分图

    这个题真的是太神了... 从一開始枚举到最后n方的转化,各种优化基本都用到了极致.... FQW的题解写了好多,个人感觉我全然没有在这里废话的必要了 直接看这里 各种方法真的是应有尽有 大概说下 首先 ...

  9. spring 加载配置文件的相关配置总结

    PropertyPlaceholderConfigurer      注意: Spring容器仅允许最多定义一个PropertyPlaceholderConfigurer(或<context:p ...

  10. Jsp指令有那些?

    <%@page language="java" contentType="text/html;charset=gb2312" session=" ...