Python在学习
来源:互联网 发布:佳明飞耐时3软件 编辑:程序博客网 时间:2024/06/04 18:11
Question 1
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.
def list_co(n): results = [] numbers = range(2, n, 1) while len(numbers) != 0: results.append(numbers[0]) j = len(numbers) while 1: if numbers[j-1] % results[-1] == 0: del numbers[j-1] j -= 1 if j <= 0: break; return len(results) print "when n is instead 100, the length of results is ", list_co(100), " ."print "when n is instead 1000, the length of results is ", list_co(1000), " ."
0 0
- 最近在学习python
- Python在学习
- 最近在学习python
- 在codecademy上学习Python
- 在学习python的阶段的态度
- Scikit Learn: 在python中机器学习
- Scikit Learn: 在python中机器学习
- Scikit Learn: 在python中机器学习
- Scikit Learn: 在python中机器学习
- Scikit Learn: 在python中机器学习
- Scikit Learn: 在python中机器学习
- Scikit Learn: 在python中机器学习
- Scikit Learn: 在python中机器学习
- Scikit Learn: 在python中机器学习
- [Python 学习] 二、在Linux平台上使用Python
- HeadFirst Python——在windows下学习Python
- python学习之--在windows上安装python模块
- 利用python在gnuradio下写一个block(python 学习)
- 安装ubuntu14.04之后无法在右上角打开system settings的解决方法
- 中国剩余定理
- 中博诚通的淘宝知识产权已通过审核
- Mybatis类型转换
- 反射
- Python在学习
- 10月份总结
- iOS开发之:手势(tap、pinch、rotation、swipe、pan、longpress)
- Android - 监听Activity点击无效
- IOS突破限制--7
- 杂记
- Android Widget组件ScrollView
- The 2012 Rocky Mountain Regional Contest 题解
- Samza/Kafka机理解析