python算法编程_Python算法编程

展开全部

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值