Python学习
java_slin
这个作者很懒,什么都没留下…
展开
-
Python 学习 one
height=float(input('Input your height:'))weight=float(input('Input your weight:'))bmi=float(weight/(height*height))if bmi<18.5: print('体重过轻')elif (bmi>=18.5 and bmi<25): print('正常')eli...原创 2018-03-17 10:16:38 · 186 阅读 · 0 评论 -
汉诺塔问题(递归)最清晰的回答 python
转自知乎https://www.zhihu.com/question/37152936重点其实是:不要一开始就关心每一步怎么解决的,你只需要把函数当成一个实现你目的的神器,随时调用。也就是递归。比如说我们有一个万能神器move,只需要给它几个参数,即可自动完成一个功能:把n个盘子利用缓冲区,从起点运送到终点,期间严格遵守汉诺塔规则move(N,起点,缓冲区,终点) N: 盘子的个数现在有个n个盘子...转载 2018-03-17 10:56:26 · 196 阅读 · 0 评论 -
Python 求1000以内素数
先构造从3开始的奇数数列def _odd_iter(): n=1 while True: n=n+2 yield n判断函数def _not_divisible(n): return lambda x: x % n>0返回素数函数def primes(): yield 2 it = _odd_iter() while True: n=next(it) yield ...原创 2018-03-19 16:31:02 · 4602 阅读 · 0 评论 -
Python 回文数问题
def is_palindrome(n): return str(n)==str(n)[-1::-1]测试output = filter(is_palindrome, range(1, 1000))print('1~1000:', list(output))if list(filter(is_palindrome, range(1, 200))) == [1, 2, 3, 4, 5, 6, ...原创 2018-03-19 16:33:15 · 1092 阅读 · 0 评论