EE308 Lab2

qq_60095079 2022-10-28 00:39:49
The Link Your Classhttps://bbs.csdn.net/forums/MUEE308FZU202201
The Link of Requirement of This Assignment

https://bbs.csdn.net/topics/608745426

The Aim of This AssignmentFor independent programming, version control(git)
MU STU ID and FZU STU ID20124856_832001222

1.PSP form for this work.

Process StagesWorkTime
Pre-workRead the requirements and install git25min
DesignDesign program execution flow30min
CodingCoding implementation process30min
TestThe output of the test code10min
CommitSubmit the code to GitHub5min
FinalSum up the experience 30min

 

GitHub:PassWordddd/Lab1-2 (github.com)

2.Problem-solving ideas

1.How to Read a File

2.How do I get the code in the file

3.How do I remove symbols from my code

4.Design data structures to hold statistical results

3.Implementation process.

 4.Code description

4.1 Read the code in the file and remove symbols

while line:
    line = f.readline()
    line = line[:-1]
    line = line.replace("else if", "else-if")
    x = re.split(' |\(|\;|\\t|\:|\{|\/\/', line)
    for i in x:
        for j in range(kwd_len):
            if i == kwdlst[j]:
                if i == "switch":
                    num0s.append(num0)
                    num0 = 0
                if i == "case":
                    num0 += 1
                count[j] += 1
    for i in x:
        if i == "if" or i == "else" or i == "else-if":
            sentences.append(x)
            continue
f.close()

4.2 Statistics the total number of all keywords & Switch-case

for i in range(kwd_len):
    if count[i] != 0:
        sumres += count[i]
        if (i == 30):
            sumres += count[i]

4.3 Statistics of the if if-else if-else-if-else structure

for j in range(x_len):
    for i in sentences:
        if i[j] == "if":
            flag_if = 1
        if i[j] == "else-if":
            flag_else_if = 1
        if i[j] == "else":
            if flag_else_if == 1:
                num_if_else_if_else += 1
            elif flag_if == 1:
                num_if_else += 1
            flag_else_if = 0
            flag_else = 0

5.Test results

"D:\Program Files\Python38\python.exe" D:\worksapce\lab1-2\Lab2.py 
level of stastic (from 1 to 4): 4
sum :  35
switch  num :  2
case num [3, 2]
if-else num: 1
if-elseif-else num: 1

6.Summarize

In this assignment, I learned the combination of git and PyCharm and the importance of version control in code development, which laid a solid foundation for future code development. 

 

...全文
119 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

285

社区成员

发帖
与我相关
我的任务
社区描述
福州大学 梅努斯国际工程学院 软件工程(2022秋) 教学
软件工程 高校
社区管理员
  • LinQF39
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧