欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python每日一练

程序员文章站 2022-03-15 22:44:18
...

前言

人生苦短,我用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]


def statics():
    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


def main():
    group_results = statics()
    index = 0
    for result in group_results:
        print ("the group {index} is :{grade}\n".format(index=index + 1, grade=result))
        index += 1


if __name__ == '__main__':
    main()
#result:
the group 1 is :1.8000000000000003

the group 2 is :1.5

the group 3 is :1.9999999999999998

the group 4 is :0.6

the group 5 is :1.8

the group 6 is :1.3

[Finished in 0.1s]

感觉sublime有毒,控制台输出中文乱码的问题解决不了,python3计算小数时会有小数点

总结

解放双手!