285
社区成员




The Link Your Class | https://bbs.csdn.net/forums/MUEE308FZU202201 |
---|---|
The Link of Requirement of This Assignment | |
The Aim of This Assignment | For independent programming, version control(git) |
MU STU ID and FZU STU ID | 20124856_832001222 |
Process Stages | Work | Time |
Pre-work | Read the requirements and install git | 25min |
Design | Design program execution flow | 30min |
Coding | Coding implementation process | 30min |
Test | The output of the test code | 10min |
Commit | Submit the code to GitHub | 5min |
Final | Sum up the experience | 30min |
GitHub:PassWordddd/Lab1-2 (github.com)
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
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
"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
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.