Data analysis 2/23

1. The new crown virus occurred in 2019-nCoV to our country, especially in Hubei have significant impact on people's lives. Get 20 February 2020 the number of newly infected with the virus domestic provincial crown data from the Chinese Center for Disease Control website (www.chinacdc.cn), variable nCoV construct a dictionary to store this data for one day.
2. Based on the above variables dictionary, write the function Max (), return the same day, "confirmed", "suspected", "death" the largest number of number of cases and the corresponding provinces.
3. Based on the above variables dictionary, write the function total (), return the same day, "confirmed", "suspected", "death" of the total number of cases.

import collections
nCov={}
list1=[]
list2=[]
list3=[]
fileinfo=open("nCov.txt",'rt',encoding='utf-8')
for line in fileinfo:
    line=line.strip().split(" ")#转化为列表
    key=line[0]#把'a'当作字典的键
    value=line[1].split(',')#对'12,13,14,15'处理,返回一个以逗号分隔的列表['12','13','14','15']
    value=[int(x) for x in value]#把['12','13','14','15']中字符变成数字,得到[12,13,14,15] 
    nCov[key]=value
def Max(dict_nCov):
    for key in dict_nCov:
        list1.append(dict_nCov[key][0])
        list2.append(dict_nCov[key][1])
        list3.append(dict_nCov[key][2])
    for key in dict_nCov:
        if max(list1)==dict_nCov[key][0]:
                print("确诊病例最多的省是{},人数是{}".format(key,max(list1)))
    for key in dict_nCov:
        if max(list2)==dict_nCov[key][1]:
                print("疑似病例最多的省是{},人数是{}".format(key,max(list2)))
    for key in dict_nCov:
        if max(list3)==dict_nCov[key][2]:
                print("死亡病例最多的省是{},人数是{}".format(key,max(list3)))
def total():
    print("确诊病例总人数为{}\n疑似病例总人数为{}".format(sum(list1),sum(list2)))
    print('死亡病例总人数为{}'.format(sum(list3)))
Max(nCov)
total()

 

Published 115 original articles · won praise 9 · views 8125

Guess you like

Origin blog.csdn.net/weixin_43673589/article/details/104488344