-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtravel_data.py
More file actions
43 lines (31 loc) · 1.18 KB
/
travel_data.py
File metadata and controls
43 lines (31 loc) · 1.18 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
import json
import os
travel_data = {}
with open("travel data/country_travel_data.json","r") as f:
travel_data = json.load(f)
def get_average_accommodation(destination):
total_accommodation = 0
total_transport = 0
total_days=0
count = 0
accommodation_freq = {}
most_common_type = None
max_count = 0
for trip_list in travel_data.values():
for trip in trip_list:
if trip['Destination'] == destination:
total_accommodation += trip['Accommodation cost']
total_transport += trip['Transportation cost']
total_days += trip['Duration (days)']
count += 1
accom = trip['Accommodation type']
accommodation_freq[accom] = accommodation_freq.get(accom, 0) + 1
if accommodation_freq[accom] > max_count:
max_count = accommodation_freq[accom]
most_common_type = accom
if count == 0:
return None
avg_accom = total_accommodation / count
avg_trans = total_transport / count
avg_days = int(total_days/count)
return avg_accom, avg_trans,avg_days, most_common_type, destination