-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex39.py
72 lines (50 loc) · 1.71 KB
/
ex39.py
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
#Link diafram of abbreviations with country names
states = {
'Russia':'RU',
'Germany':'DE',
'Uzbekistan':'UZ',
'Zimbabwe':'ZW',
'Turkey':'TR'
}
#Creation of a basic of countries and some cities in them
cities = {
'UZ':'Gazli',
'TR':'Sarygerme',
'DE':'Munich'
}
#adding multiple cities
cities['ZW'] = 'Gveru'
cities['RU'] = 'Moscow'
#withdrawal of some cities
print('-' * 10)
print('In the country ZW there is a city: ', cities['ZW'])
print('In the country RU there is a city ', cities['RU'])
#Withdrawal of some countries
print('-' * 10)
print('Abbreviation Turkey: ', states['Turkey'])
print('Abbreviation Germany:', states['Germany'])
#Performed taking into account the country and the dictionary of cities
print('-' * 10)
print('There is a city in Turkey: ', cities[states['Turkey']])
print('There is a city in Germany: ', cities[states['Germany']])
#Display of abbreviations of all countries
print('-' * 10)
for state, abbrev in list(states.items()):
print(f"{state} has an Abbreviation {abbrev}")
#Output of all cities in countries
print('-' * 10)
for abbrev, city in list(cities.items()):
print(f"In the country {abbrev} there is a city {city}")
#And now both data types at once
print('-' * 10)
for state, abbrev in list(states.items()):
print(f"In the country {state} abbreviation used {abbrev}")
print(f"And there is a city {cities[abbrev]}")
print('-' * 10)
#safely getting the abbreviation of a country that is not represented
state = states.get('USA')
if not state:
print("I'm sorry, the USA does not exist or has been destroyed.")
#Getting city with default value
city = cities.get('US', 'does not exist')
print(f"In the country 'US' there is a city: {city}")