kewin-python Offered rate calculation king of glory

More children's programming can contact Hou, micro-channel data_ecology
This link: https://blog.csdn.net/houlaos/article/details/102648944
# 1。选个队伍
import random
team = ['百里守约', '曹操', '扁鹊', '诸葛亮', '赵云']
join = []
for i in range(random.randint(100,300)):
    join.append(team[random.randint(0, 4)])
print(team)
print(join)
# 参战率 '扁鹊':15, '赵云':13
# 设置一个空字典
q={}
# for循环把join里的英雄提取出来
for w in join:
    # 提取的这一个英雄在不在这个字典里
    if w  not in q:
        q[w]=1
    # 如果在的话,给这个键值对的值+1 if   in
    elif w in q:
        q[w]=q[w]+1
print(q)
    # 如果不在的话,可以新建一个键值对

Guess you like

Origin blog.csdn.net/houlaos/article/details/102648944