-
Notifications
You must be signed in to change notification settings - Fork 0
/
简易的中文语言编译器
113 lines (113 loc) · 2.43 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def 输入():
str = input()
s = str.split()
if len(s)>0:
if s[0] == '整数':
what[0] = s[1]
elif s[0] == '看看' or '如果':
what[0] = s[1]
else:
what[0] = s[0]
return s
else:
return None
def 汉转数(s):
if len(s) <= 2:
s[1] = s[1]
elif s[2] == '零':
s[2] = 0
elif s[2] == '一':
s[2] = 1
elif s[2] == '二':
s[2] = 2
elif s[2] == '三':
s[2] = 3
elif s[2] == '四':
s[2] = 4
elif s[2] == '五':
s[2] = 5
elif s[2] == '六':
s[2] = 6
elif s[2] == '七':
s[2] = 7
elif s[2] == '八':
s[2] = 8
elif s[2] == '九':
s[2] = 9
elif s[2] == '十':
s[2] = 10
elif s[3] == '零':
s[3] = 0
elif s[3] == '一':
s[3] = 1
elif s[3] == '二':
s[3] = 2
elif s[3] == '三':
s[3] = 3
elif s[3] == '四':
s[3] = 4
elif s[3] == '五':
s[3] = 5
elif s[3] == '六':
s[3] = 6
elif s[3] == '七':
s[3] = 7
elif s[3] == '八':
s[3] = 8
elif s[3] == '九':
s[3] = 9
elif s[3] == '十':
s[3] = 10
return s
def 数转汉():
if what[1] == 0:
what[3] = '零'
elif what[1] == 1:
what[3] = '一'
elif what[1] == 2:
what[3] = '二'
elif what[1] == 3:
what[3] = '三'
elif what[1] == 4:
what[3] = '四'
elif what[1] == 5:
what[3] = '五'
elif what[1] == 6:
what[3] = '六'
elif what[1] == 7:
what[3] = '七'
elif what[1] == 8:
what[3] = '八'
elif what[1] == 9:
what[3] = '九'
elif what[1] == 10:
what[3] = '十'
return s
def 使用(s):#只考虑了加减运算
#第一句话
if (s[0]=='整数') and (s[2]=='等于'):
what[1] = s[3]
#第二句话
if s[1] == '减少':
what[1] = what[1] - s[2]
#第三句话
if s[1] == '增加':
what[1] = what[1] + s[2]
#第四句话
if s[0] == '看看':
数转汉()
print(what[3])
#第五句话
if s[0] == '如果':
if s[2] == '大于':
if what[1] > s[3]:
print(s[6])
else:
print(s[9])
if __name__ == '__main__':
what = ['',0,0,'']
while(1):
s = 输入()
if s != None:
s = 汉转数(s)
使用(s)