Easy Chinese language translator

This work belongs courses https://edu.cnblogs.com/campus/fzzcxy/SE
Where the job requires https://edu.cnblogs.com/campus/fzzcxy/SE/homework/10283
The target job <Make a simple Chinese language compiler>
Text of the job https://github.com/287928201/-
Other references The students code Baidu search

1. Record number of their own lines of code, requirements analysis time and coding time.

Of 113 lines of code.
Analysis time: 2 hours.
Encoding time: one afternoon a night.

2. Decomposition demand ideas, broken down into multiple modules, and explains why so many points advantage which can attach code snippets.

Written in python, I feel easy with py write, without headers, but during the operation is too much trouble, can not be replicated along the whole input, you need to copy a sentence.

Enter the fragment

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

Character segments digital conversion

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

Computing fragment

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])

Use fragments

if __name__ == '__main__':
    what = ['',0,0,'']
    while(1):
        s = 输入()
        if s != None:
            s = 汉转数(s)
            使用(s)

3. The record is not learning process knowledge and optimization of process modifications; you can add information on the site.

An array of character conversion section and section forget that many, str int type and type of error often leads to inconsistency. Reference to the many students of code.

4. Test Sample

Guess you like

Origin www.cnblogs.com/denghui123/p/12286050.html