-
Notifications
You must be signed in to change notification settings - Fork 4
/
ex8-fishing-in-the-nordics
52 lines (41 loc) · 1.95 KB
/
ex8-fishing-in-the-nordics
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
#!/usr/bin/env python
# --------------------------------------------------------------------------------------------------------- Intermediate
def main():
countries = ['Denmark', 'Finland', 'Iceland', 'Norway', 'Sweden']
populations = [5615000, 5439000, 324000, 5080000, 9609000]
fishers = [1891, 2652, 3800, 11611, 1757]
total_pop = sum(populations)
total_fishers = sum(fishers)
cond_pop = []
for j in range(len(countries)):
cond_pop.append(fishers[j] / total_fishers * 100)
for country,cond_pop in zip(countries, cond_pop):
print("%s %.2f%%" % (country, cond_pop)) # modify this to print correct results
main()
# --------------------------------------------------------------------------------------------------------- Advanced
countries = ['Denmark', 'Finland', 'Iceland', 'Norway', 'Sweden']
populations = [5615000, 5439000, 324000, 5080000, 9609000]
male_fishers = [1822, 2575, 3400, 11291, 1731]
female_fishers = [69, 77, 400, 320, 26]
def guess(winner_gender):
if winner_gender == 'female':
fishers = female_fishers
else:
fishers = male_fishers
# write your solution here
total_Population = sum(populations)
fishers_Total = sum(fishers)
temp_ans = (populations[0] / total_Population) * (fishers[0] / populations[0])
for j in range(len(populations)):
starting = (populations[j] / total_Population) * (fishers[j] / populations[j])
if starting > temp_ans:
temp_ans = (populations[j] / total_Population) * (fishers[j] / populations[j])
guess = countries[j]
biggest = fishers[j] / fishers_Total * 100
return (guess, biggest)
def main():
country, fraction = guess("male")
print("if the winner is male, my guess is he's from %s; probability %.2f%%" % (country, fraction))
country, fraction = guess("female")
print("if the winner is female, my guess is she's from %s; probability %.2f%%" % (country, fraction))
main()