Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
22 lines (18 loc) · 735 Bytes

File metadata and controls

22 lines (18 loc) · 735 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# -*- coding:utf-8 -*-
__author__ = 'gjw'
__time__ = '2018/1/8 0008 上午 9:30'
# 题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个第二天早上又将剩下的桃子吃掉一半,又多吃了一个。
# 以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。
# 程序分析:采取逆向思维的方法,从后往前推断。
x = 1
for d in range(9, 0, -1):
r = (x+1)*2
x = r
print("第一天摘了:"+str(r))
# 改进版
print()
print("我是改进版")
x = 1
for d in range(9, 0, -1):
x = (x+1)*2
print("第"+str(d)+"天摘了:"+str(x))
Morty Proxy This is a proxified and sanitized view of the page, visit original site.