-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnalyzing Data.py
More file actions
107 lines (82 loc) · 3.17 KB
/
Copy pathAnalyzing Data.py
File metadata and controls
107 lines (82 loc) · 3.17 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
chosen_year = int(input("\nEnter the year of interest: "))
print("")
# stat_list = []
# code_list = []
# year_list = []
# life_list = []
min_life = 9999
countries_from_min = None
year_from_min = None
max_life = -1
countries_from_max = None
year_from_max = None
with open("life-expectancy.csv") as new_file:
for data in new_file:
new_data = data.strip()
part = new_data.split(",")
state = part[0]
code = part[1]
year = int(part[2])
life_expectatancy = float(part[3])
# stat_list.append(state)
# code_list.append(code)
# year_list.append(year)
# life_list.append(life_expectatancy)
if life_expectatancy < min_life:
min_life = life_expectatancy
countries_from_min = state
year_from_min = year
if life_expectatancy > max_life:
max_life = life_expectatancy
countries_from_max = state
year_from_max = year
print(f"The overall max life expectancy is: {max_life} from {countries_from_max} in {year_from_max}")
print(f"The overall min life expectancy is: {min_life} from {countries_from_min} in {year_from_min}\n")
min_life = 9999
countries_from_min = None
year_from_min = None
suma = 0
count = 0
max_life = -1
countries_from_max = None
year_from_max = None
with open("life-expectancy.csv") as new_file:
for data in new_file:
new_data = data.strip()
part = new_data.split(",")
state = part[0]
code = part[1]
year = int(part[2])
life_expectatancy = float(part[3])
# stat_list.append(state)
# code_list.append(code)
# year_list.append(year)
# life_list.append(life_expectatancy)
if year == chosen_year:
count += 1
suma += life_expectatancy
if life_expectatancy < min_life:
min_life = life_expectatancy
countries_from_min = state
year_from_min = year
if life_expectatancy > max_life:
max_life = life_expectatancy
countries_from_max = state
year_from_max = year
avg = suma / count
print(f"For the year {chosen_year}:")
print(f"The average life expectancy across all countries was {avg:.2f}"
f"\nThe max life expectancy was in {countries_from_max} with {max_life}"
f"\nThe min life expectancy was in {countries_from_min} with {min_life}\n")
# number_max = -1
# for number in life_list:
# if number > number_max:
# number_max = number
# position_max = life_list.index(number_max)
# number_min = 99999999999
# for number in life_list:
# if number > 0 and number < number_min:
# number_min = number
# position_min = life_list.index(number_min)
# print(f"The overall max life expectancy is: {number_max} from {stat_list[position_max]} in {year_list[position_max]}")
# print(f"The overall min life expectancy is: {number_min} from {stat_list[position_min]} in {year_list[position_min]}")