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. JAVA泛型实现一个堆栈类

    package com.xt.test; /** * 泛型实现堆栈,thinking in java中的例子 * * @author Administrator * * @param <T> ...

  2. director.js教程

    directive.js 初始化和注册路由 director.js 的主要对象是Router对象,构造方法如下: var router = new Router(routes); //routes为路 ...

  3. Linux搭建FTP

    Linux FTP 服务器配置简单说明 转载:http://blog.csdn.net/tianlesoftware/article/details/6151317

  4. Static block start new thread

    Static block start new thread public class StaticThreadInit { static{ Threadt = newThread(){ public ...

  5. <td style="word-break:break-all"> 在html中控制自动换行

    在html中控制自动换行   其实只要在表格控制中添加一句 <td style="word-break:break-all">就搞定了. 其中可能对英文换行可能会分开一 ...

  6. ANDROID自己定义视图——onLayout源代码 流程 思路具体解释

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 简单介绍: 在自己定义view的时候.事实上非常easy.仅仅须要知道3步骤: 1.測量- ...

  7. 苹果 App 转移图文详解

    目前公司在做App转移操作,在网上搜索相关资料加上自己的亲自操作,整理成一个文档,希望能给你提供帮助. 如转载请添加出处. 此文章只是为了记录一个Apple ID下的APP,转移到另外一个Apple ...

  8. web浏览器中的javascript 1

    Html 文档嵌入客户端有4种方式. 1. 内联.放置在<script>和</script>标签对之间. 2.放置在<script>标签的src属性指定的外部文件中 ...

  9. css3的一些属性

    以前还没有注意过css的一些属性,近期发现有一些样式很好用,现在整理一遍. CSS3 动画属性 @keyframes : 规定动画 可以通过keyframes 改变一个块的样式当然这是要配合anima ...

  10. slots

    class Student(object): pass s = Student() s.name = 'Michael' print(s.name) def set_age(self, age): s ...