-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex48.py
32 lines (24 loc) · 808 Bytes
/
ex48.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
D = {'direction': ['north', 'south', 'east','west', 'down', 'up', 'left', 'right', 'back'],
'verb': ['go', 'stop', 'kill', 'eat'],
'stop': ['the', 'in', 'of', 'from', 'at', 'it'],
'noun': ['door', 'bear', 'princess', 'fighter','cabinet']
}
def convert_numbers(word):
try:
return int(word)
except ValueError:
return None
def scan(sentence):
words = sentence.split(" ")
res = []
for word in words:
if convert_numbers(word) != None:
res.append(('number', convert_numbers(word)))
else:
type = 'error'
for t in D:
if word.lower() in D[t]:
type = t
break
res.append((type, word)) # error for res=res.append()
return res