人生苦短,我用python【2018.6.13】
最近事情有點多,有幾天沒寫了,正好最近需要統計一下各組排名,也就拿python代替手工了
各組給出其他組的排名,統計每個組最終的得分,第一名為0.5,第二名0.4,以此類推。
# -*- coding:utf-8 -*-
groups = [[3, 2, 5, 4, 6], [1, 3, 5, 6, 4], [5, 6, 1, 2, 4], [3, 2, 1, 5, 6], [6, 3, 1, 2, 4], [5, 1, 2, 3, 4]]
score = [0.5, 0.4, 0.3, 0.2, 0.1]
group_results = [0, 0, 0, 0, 0, 0]
defstatics
():for group in groups:
for index in range(0, 5):
if group[index] == 1:
group_results[0] += score[index]
if group[index] == 2:
group_results[1] += score[index]
if group[index] == 3:
group_results[2] += score[index]
if group[index] == 4:
group_results[3] += score[index]
if group[index] == 5:
group_results[4] += score[index]
if group[index] == 6:
group_results[5] += score[index]
return group_results
defmain
(): group_results = statics()
index = 0
for result in group_results:
print ("the group is :\n".format(index=index + 1, grade=result))
index += 1
if __name__ == '__main__':
main()
感覺sublime有毒,控制台輸出中文亂碼的問題解決不了,python3計算小數時會有小數點#result:
the group
1is :1.8000000000000003
the group
2is :1.5
the group
3is :1.9999999999999998
the group
4is :0.6
the group
5is :1.8
the group
6is :1.3
[finished in
0.1s]
解放雙手!
python每日一練
人生苦短,我用python 2018.6.5 有個目錄,裡面是你自己寫過的程式,統計一下你寫過多少行 包括空行和注釋,但是要分別列出來 coding utf 8 import re import glob defcodecolletion path filelist glob.glob path p...
Python每日一練0002
如何序列化輸出元素包含字串元組的字串元組 好繞 舉個例子 zoo1 monkey elephant zoo2 python zoo1 將zoo2輸出為python,monkey,elephant容易想到使用join 函式,但join 函式要求元素必須都是字串型別,否則會丟擲typeerror錯誤 z...
Python每日一練0008
怎樣在兩個字典中尋尋找相同點 比如相同的鍵 相同的值等等 直接對keys 或者items 使用集合操作,比如 差 並 交 考慮下面兩個字典 a b 要找到相同的key,可以對keys做 操作 print a.keys b.keys 也可以使用這一特性來對字典過濾,例如去掉集合a中key為x和y兩個元...