Quiz 6b Question 7————An Introduction to Interactive Programming in Python
来源:互联网 发布:瑞安司法淘宝网拍卖 编辑:程序博客网 时间:2024/04/27 23:52
Question 7
Convert the following English description into code.
- Initialize
n
to be 1000. Initialize numbers
to be a list of numbers from 2 to n, but not including n
. - 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 lisprint len(res)
Convert the following English description into code.
- Initialize
n
to be 1000. Initializenumbers
to be a list of numbers from 2 to n, but not includingn
. - With
results
starting as the empty list, repeat the following as long asnumbers
contains any numbers.- Add the first number in
numbers
to the end ofresults
. - Remove every number in
numbers
that is evenly divisible by (has no remainder when divided by) the number that you had just added toresults
.
- Add the first number in
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 lisprint len(res)
0 0
- Quiz 6b Question 7————An Introduction to Interactive Programming in Python
- Quiz 6b Question 8————An Introduction to Interactive Programming in Python
- Quiz 6a Question 7————An Introduction to Interactive Programming in Python
- An Introduction to Interactive Programming in Python
- An Introduction to Interactive Programming in Python(week 6)
- An Introduction to Interactive Programming in Python(week 7)
- An Introduction to Interactive Programming in Python - Week zero
- An Introduction to Interactive Programming in Python - Week one
- An Introduction to Interactive Programming in Python - Week two
- An Introduction to Interactive Programming in Python - Week three
- An Introduction to Interactive Programming in Python week 9
- An Introduction to Interactive Programming in Python (Part 2) week 6 (Classes and Tied images)
- An Introduction to Interactive Programming in Python (Part 2) -- Week 7 More Classes & Sprites
- [Coursera][Rice] An introduction to interactive Programming in Python Week 1
- 【coursera 学习笔记】An Introduction to Interactive Programming in Python--week0
- 【coursera 学习笔记】An Introduction to Interactive Programming in Python--week1
- [Coursera][Rice] An introduction to interactive Programming in Python Week 2 3
- An Introduction to Interactive Programming in Python 第四课作业 Pong
- HDU 1166 排兵布阵(线段树)
- Spring IO Platform
- Theme中设置动画
- 线段树区间更新——POJ 2777
- 唯一分解定理
- Quiz 6b Question 7————An Introduction to Interactive Programming in Python
- 微信平台公共账号服务号与订阅号之间的区别
- 给这个问题一个最没有悬念的答案
- 生产管理: Wagner-Whitin算法
- Sicily 1063 Time Limit Exceeded我日
- Android初学之数据库的操作
- java序列化和反序列化的简单实现
- 数据结构中用图的邻接矩阵的表示以及深度搜索
- Mac 下安装Mysql