题目很容易,只要理清了数学思想就可以解出来,所以本来不是很喜欢这种题。

后来看到有大神用递归解,觉得还是很值得学习的。

原题链接:http://www.runoob.com/python/python-exercise-example21.html

题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。

我的代码:

x=1
for i in range(0,9):    #注意是1天到10天,吃了9次
x=(x+1)*2
print(x)

看了递归思想后学写的代码:

def peach(n):
if n==1:
return 1
else:
return (peach(n-1)+1)*2   #n=10 这一行代码也是运行了9次  print(peach(10))  

python3练习100题——021的更多相关文章

  1. python3练习100题——003

    今天继续-答案都会通过python3测试- 原题链接:http://www.runoob.com/python/python-exercise-example3.html 题目:一个整数,它加上100 ...

  2. python3练习100题——002

    因为特殊原因,昨天没有做题.今天继续- 原题链接:http://www.runoob.com/python/python-exercise-example2.html 题目: 企业发放的奖金根据利润提 ...

  3. python3练习100题——004

    继续做题-经过python3的测试 原题链接:http://www.runoob.com/python/python-exercise-example4.html 题目:输入某年某月某日,判断这一天是 ...

  4. python3练习100题——036

    原题链接:http://www.runoob.com/python/python-exercise-example36.html 题目:求100之内的素数. 之前有类似的题,所以这次遇到觉得很容易了, ...

  5. python3练习100题——035

    原题链接:http://www.runoob.com/python/python-exercise-example34.html 题目:文本颜色设置. 学习了一下python3 的文本颜色设置. 其实 ...

  6. python3练习100题——020

    原题链接:http://www.runoob.com/python/python-exercise-example20.html 题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半:再落下 ...

  7. python3练习100题——013

    熟悉的水仙花数来了,,,... 原题链接:http://www.runoob.com/python/python-exercise-example13.html 题目:打印出所有的"水仙花数 ...

  8. python3练习100题——056

    题目:画图,学用circle画圆形. 可以用turtle.circle画图. import turtle turtle.setup(0.6,0.6) turtle.pensize(3) turtle. ...

  9. python3练习100题——050

    题目:输出一个随机数. 程序分析:使用 random 模块. import random print( random.randint(1,10) ) # 产生 1 到 10 的一个整数型随机数 pri ...

随机推荐

  1. 浅谈python的第三方库——numpy(终)

    本文作为numpy系列的总结篇,继续介绍numpy中常见的使用小贴士 1 手动转换矩阵规格 转换矩阵规格,就是在保持原矩阵的元素数量和内容不变的情况下,改变原矩阵的行列数目.比如,在得到一个5x4的矩 ...

  2. Centos7 虚拟机安装增强功能

    1 yum update kernel -y yum install kernel-headers  kernel-devel gcc make -y init 6 2 菜单栏--设备--安装增强工具 ...

  3. java-标准输入

    package InputDemo; public class InputDemo1 { public static void main(String[] args) { /* 1. java.uti ...

  4. linux 下查看json 文件 使用jq工具

    安装 文档 yum 安装 yum search jq yum -y install jq.x86_64 apt-get install jq jq支持查看 jq . json 文件 查看json文件 ...

  5. iframe中子父页面跨域通讯

    目录 #跨域发送信息 #跨域接收信息 #示例Demo 在非跨域的情况下,iframe中的子父页面可以很方便的通讯,但是在跨域的情况下,只能通过window.postMessage()方法来向其他页面发 ...

  6. C# compare different Encoding pattern between UTF8 and UTF32 based on Md5

    using System; using System.Text; using System.IO; using System.Security.Cryptography; static void Ma ...

  7. css样式-区域内文字不会被选中

    要注意浏览器的兼容性: -webkit-user-select:none; -moz-user-select:none; -ms-user-select:none; user-select:none;

  8. ECMAScript基本对象——RegExp 正则表达式对象

    含义:定义字符串的组成规则 使用: 1.定义单个字符:[ ] [a] 表示有一个字符是  小写的a [ab] 表示有一个字符是  小写的a或者b [a-z] 表示有一个字符是  小写的a到z [a-z ...

  9. react 中 函数bind 和箭头函数

    用bind形式 方便测试,含有this时候最好用bind形 其他情况用箭头函数 含有this的时候也可以用箭头函数

  10. C语言实现链式二叉树静态创建,(先序遍历),(中序遍历),(后续遍历)

    #include <stdio.h>#include <stdlib.h> struct BTNode{ char data ; struct BTNode * pLchild ...