-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise3.py
More file actions
executable file
·65 lines (37 loc) · 1.04 KB
/
exercise3.py
File metadata and controls
executable file
·65 lines (37 loc) · 1.04 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
'''
Write a program that asks a user to choose a word from its list and gives the user the meaning of that word.
If the word entered by the user is not in the program's list, the program should alert the user that the word does not exist in the list.
The program should ask the user whether they want to continue to search for word meanings or else type 'exit' to stop searching.
'''
cities = {
'Kenya' : 'Nairobi',
'Uganda': 'Kampala',
'Rwanda': 'Kigali',
'Tanzania' : 'Dodoma'
}
#get input from a user
def getInput():
find = raw_input('Enter a Country to search its capital or exit to Quit\n')
return find
#search function
def search(var):
for key in cities:
if key == var:
status = cities[key]
break
else:
status = 'not found'
return status
def finder():
running = True
while running:
userInput = getInput()
if userInput == 'exit':
running = False
else:
value = search(userInput)
if value != 'not found':
print 'The city is ',value
else:
print 'Not Found'
finder()