tuple demo
2015-07-08 08:20
357 查看
#quote from MIT 'introduction to computation and programming using python, Revised' def findDivisors(n1, n2): """Assumes that n1 and n2 are positive ints Returns a tuple containing all common divisors of n1 & n2""" divisors = () #the empty tuple for i in range(1, min(n1, n2) + 1): if n1%i == 0 and n2%i == 0: divisors += (i,) return divisors divisors = findDivisors(20, 100) print divisors total = 0 for d in divisors: total += d print total
%run "C:\Users\Administrator\test.py"
(1, 2, 4, 5, 10, 20)
42
相关文章推荐
- Win10 Mobile预览版10149慢速版正式推送
- 如何解决KEIL 5 编KEIL4同RTX系统的project解
- 全新E:网站不是之前排名浮动 相比于竞争对手究竟缺少了什么?
- Windows 10 10149手机预览版在慢车道开始推送
- 7.7模拟总结
- Csharp学习第二天
- 【剑指Offer学习】【面试题44:扑克牌的顺子】
- maven常用配置
- Android.os.SystemClock
- 为什么事务日志自动增长会降低你的性能
- C#第五次作业:开源项目“网页正文提取”的理解
- CentOS系统时间与网络同步
- leetCode(33):Rectangle Area
- 主席树修正
- leetCode(33):Rectangle Area 分类: leetCode 2015-07-08 08:06 125人阅读 评论(0) 收藏
- Csharp学习第一天
- 2-11章 笔记
- Android自定义标题和按钮效果(附源码)
- Palindrome using recursion
- 从偶然的机会发现一个mysql特性到wooyun waf绕过题