展开全部
1题:Staff.txt 员工信32313133353236313431303231363533e4b893e5b19e31333335343961息单
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 python
print filter(lambda x: x % 3 == 0 and x % 5 != 0,range(1000))
3题:#!/usr/bin/env python
sum1 = 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 python
sum1 = 0
count = 6
def height(x):
if x == 10:
return 0
return (height(x+1)+1)*2
print height(0)