#!/bin/python3.4
# Coding=utf-8
Class Lexicon (Object):
# direction = [' North ', ' South ', ' East ', ' West ']
# verb = [' go ', ' Stop ', ' kill ', ' eat ']
# noun = [' door ', ' Bear ', ' princess ', ' cabinet ']
# num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
# wordtypelist = [direction, verb, noun, num]
Def__INIT__ (Self, name):
Self.name = Name
Print"Class name is%s."Self.name
DEF scan (Elements):
Direction = [' North ',' South ',' East ',' West ']
verb = [' Go ',' Stop ',' Kill ',' Eat ']
noun = [' Door ',' Bear ',' Princess ',' Cabinet ']
num = [0,1,2,3,4,5,6,7,8,9,0]
Wordtypelist = [direction, verb, noun, num]
elements =Raw_input (">>")
element =Elements.split ()
For IInchRangeLenelements)):
Count = I
If elementIn wordtypelist[0]:
Print"Num:%d type:%s element:%s"% (count, wordtypelist[0], Element))
elif elementIn wordtypelist[0][
Print"Num:%d type:%s element:%s"% (count, wordtypelist[1], Element))
elif elementIn wordtypelist[2]:
Print2], Element))
else:
print (" num:%d type:%s element:%s "% (count, Wordtypelist[3], Element))
if __name__ = print ( "##### Start #####")
Stuff = Lexicon ( "Lexicon")
Stuff.scan ()
print (" ##### End ##### ")
#!/bin/python3.4
# Coding=utf-8
Class Lexicon (Object):
# direction = [' North ', ' South ', ' East ', ' West ']
# verb = [' go ', ' Stop ', ' kill ', ' eat ']
# noun = [' door ', ' Bear ', ' princess ', ' cabinet ']
# num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
# wordtypelist = [direction, verb, noun, num]
Def__INIT__ (Self, name):
Self.name = Name
Print"Class name is%s."Self.name
DEF scan (Elements):
Direction = [' North ',' South ',' East ',' West ']
verb = [' Go ',' Stop ',' Kill ',' Eat ']
noun = [' Door ',' Bear ',' Princess ',' Cabinet ']
num = [0,1,2,3,4,5,6,7,8,9,0]
Wordtypelist = [direction, verb, noun, num]
elements =Raw_input (">>")
element =Elements.split ()
For IInchRangeLenelements)):
Count = I
If elementIn wordtypelist[1][
Print"Num:%d type:%s element:%s"% (count, wordtypelist[0], Element))
elif elementIn wordtypelist[1]:
Print"Num:%d type:%s element:%s"% (count, wordtypelist[1], Element))
elif elementIn wordtypelist[2]:
PrintNum:%d type:%s element:%s "% (count, wordtypelist[2], Element))
Else:
print ("num:%d type:%s element:%s"% (count, wordtypelist[3], Element))
if __name__ = = ' __main__ ':
print ("##### Start #####")
Stuff = Lexicon ("Lexicon")
Stuff.scan ()
print ("##### End #####")
Execution Result:
[email protected] conwaygame.py]# python ex48.py
##### Start #####
Class name is lexicon.
>> Eat the Python
num:0 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:1 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:2 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:3 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:4 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:5 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:6 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:7 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:8 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:9 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:10 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:11 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:12 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
Num:13 type: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0] element: [' eat ', ' the ', ' Python ']
##### End #####
 
Code checking for Python