设原来有:5X+1
第二只拿走后还有:4Y=5Z+1
第三只拿走后还有:4Z=5M+1
第四只拿走后还有:4M=5N+1
则第五只猴拿走的桃子为:N个
楼主可假设N=1,2,3....
直至使得X,Y,Z,M均为整数即符合题意.
逆推法设最后每分1个,多1,那么是6
那么第4次是6*5+1=31
第3次是31*5+1=156
第2次156*5+1=781
第1次781*5+1=3906
1题:
Staff.txt 员工信息单1 4000
2 5000
3 6000
4 7000
5 7000
6 8000
7 10000
8 12000
9 15000
10 20000
运行脚本:
#!/usr/bin/env python
class Tax:
def __init__(self,name,wage):
self.name = name
self.wage = float(wage)
def tax(self):
if self.wage <= 3000:
print self.name,' tax is 0'
elif self.wage <= 6000:
print self.name, ' tax is ',self.wage * 0.05
elif self.wage <= 10000:
print self.name, ' tax is ',self.wage * 0.10
elif self.wage <= 20000:
print self.name, ' tax is ',self.wage * 0.20
elif self.wage <= 100000:
print self.name, ' tax is ',self.wage * 0.40
else:
print self.name, ' tax is ',self.wage * 0.45
with open('Staff.txt') as f:
d=f.readlines()
for i in d:
count= Tax(i.split()[0],i.split()[1])
count.tax()
执行结果:
1 tax is 200.0
2 tax is 250.0
3 tax is 300.0
4 tax is 700.0
5 tax is 700.0
6 tax is 800.0
7 tax is 1000.0
8 tax is 2400.0
9 tax is 3000.0
10 tax is 4000.0
2题:
#!/usr/bin/env pythonprint filter(lambda x: x % 3 == 0 and x % 5 != 0,range(1000))
3题:
#!/usr/bin/env pythonsum1 = 0
count = 6
def height(x):
if x == 1 or x == 2:
return 10
return float(height(x-1))/2
for i in range(1,count+1):
sum1 += height(int(i))
print sum1
4题:
#!/usr/bin/env pythonsum1 = 0
count = 6
def height(x):
if x == 10:
return 0
return (height(x+1)+1)*2
print height(0)