- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListObject.py
More file actions
Latest commit
52 lines (40 loc) · 1.44 KB
/
Copy pathListObject.py
File metadata and controls
52 lines (40 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
fromimportlib.resourcesimportopen_text
classlifelostRecord:
def__init__(self, recordstring) ->None:
#Ref_Date,GEO,SEX,CAUSES,UNIT,Value
string_list=recordstring[:-1].split(',')
self.__ref_Date=int(string_list[0])
self.__GEO=string_list[1]
self.__SEX=string_list[2]
self.__CAUSES=string_list[3]
self.__UNIT=string_list[4]
self.__Value=float(string_list[5].strip())
def__str__(self) ->str:
return (' Ref_Date: '+str(self.__ref_Date) +' GEO: '+self.__GEO+' SEX: '+self.__SEX+' CAUSES: '+self.__CAUSES+' UNIT: '+self.__UNIT+' Value: '+str(self.__Value))
defget_value(self):
returnself.__Value
defget_year(self):
returnself.__ref_Date
defget_causes(self):
returnself.__CAUSES
file=open('input/lifeLostbyCauseData.txt','r')
file_content=file.readlines()
Record_list= []
count=1
forrowinfile_content:
ifcount>1:
record=lifelostRecord(row)
Record_list.append(record)
count=count+1
#Total loft Lost
total_life_lost=0
forrecordinRecord_list:
total_life_lost=total_life_lost+record.get_value()
print(total_life_lost )
#Total lof0t Lost
year=2021
life_lost_byyear=0
forrecordinRecord_list:
ifrecord.get_year() ==year:
life_lost_byyear=life_lost_byyear+record.get_value()
print(life_lost_byyear )