-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprogram_9_Dictionary.py
More file actions
50 lines (38 loc) · 1.65 KB
/
program_9_Dictionary.py
File metadata and controls
50 lines (38 loc) · 1.65 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
# Dictionaries are paired lists
# a 'key' is used to access a value { key : value }
# Note that a dictionary is defined with '{}' a list with '[]'
statePopulation = {'Alabama' : 4779736,
'Alaska' : 710230,
'Arizona' : 6392017,
'Arkansas' : 2915918,
'California' : 37253956,
'Colorado' : 5029196,
'Conneticut' : 3574097,
'Delaware' : 879934,
'Florida' : 18801310,
'Georgia' : 9687653,
'Hawaii' : 1360301,
'Idaho' : 1567582,
'Illinois' : 12830632,
'Indiana' : 6483802,
'Iowa' : 3046355,
'Kansas' : 2853118 }
def PrintStatePopInfo():
print('My database has', len(statePopulation), 'states in it.')
totalPopulation = sum( statePopulation.values() )
print('The total population is', '{:,}'.format(totalPopulation))
def FindStatePopulation():
FindPopulation = input('Do you want to find a state population? yes/no : ')
if ( FindPopulation == 'yes' ) :
stateName = input('Enter the state you want to check ')
if stateName in statePopulation.keys() :
print('The population of', stateName,
'is', statePopulation[stateName] )
else:
print('The state', stateName, "isn't in my database.")
def main():
PrintStatePopInfo()
FindStatePopulation()
# This tells Python to run the function called main()
if __name__ == "__main__":
main()