當前位置:首頁 » 編程語言 » python演算法編程題

python演算法編程題

發布時間: 2023-07-06 03:31:23

A. python演算法編程

1題:

Staff.txt員工信息單
14000
25000
36000
47000
57000
68000
710000
812000
915000
1020000

運行腳本
#!/usr/bin/envpython

classTax:
def__init__(self,name,wage):
self.name=name
self.wage=float(wage)
deftax(self):
ifself.wage<=3000:
printself.name,'taxis0'
elifself.wage<=6000:
printself.name,'taxis',self.wage*0.05
elifself.wage<=10000:
printself.name,'taxis',self.wage*0.10
elifself.wage<=20000:
printself.name,'taxis',self.wage*0.20
elifself.wage<=100000:
printself.name,'taxis',self.wage*0.40
else:
printself.name,'taxis',self.wage*0.45

withopen('Staff.txt')asf:
d=f.readlines()
foriind:
count=Tax(i.split()[0],i.split()[1])
count.tax()

執行結果:
1taxis200.0
2taxis250.0
3taxis300.0
4taxis700.0
5taxis700.0
6taxis800.0
7taxis1000.0
8taxis2400.0
9taxis3000.0
10taxis4000.0


2題:

#!/usr/bin/envpython

printfilter(lambdax:x%3==0andx%5!=0,range(1000))


3題:

#!/usr/bin/envpython

sum1=0
count=6
defheight(x):
ifx==1orx==2:
return10
returnfloat(height(x-1))/2
foriinrange(1,count+1):
sum1+=height(int(i))
printsum1


4題:

#!/usr/bin/envpython

sum1=0
count=6
defheight(x):
ifx==10:
return0
return(height(x+1)+1)*2

printheight(0)
熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:642
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:368
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:89
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:312
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:794
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:348
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:213
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:818
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:369
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:596