这个作业属于哪个课程 | https://edu.cnblogs.com/campus/fzzcxy/SE |
---|---|
这个作业要求在哪里 | https://edu.cnblogs.com/campus/fzzcxy/SE/homework/10283 |
这个作业的目标 | |
作业正文 | https://github.com/287928201/- |
其他参考文献 | 同学代码,百度搜索 |
1.记录自己的代码行数,需求分析时间,编码时间。
代码共113行。
分析时间:2小时。
编码时间:一个下午一个晚上。
2.分解需求的思路,分解成多个模块,并阐述为什么这么分,优势在哪,可以附上代码片段。
用的python写的,觉得用py写方便,不用头文件,但是运行过程中比较麻烦,不能整段输入一起复制,需要一句一句复制。
输入片段
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)
3.记录不会的知识的学习过程以及修改优化的过程;可以附上资料网站。
数组部分和字符转换部分忘了许多,str类型和int类型的不一致导致经常报错。参考了许多同学的代码。