20181127-1附加作业 软件工程原则的应用实例
20181127-1附加作業 軟件工程原則的應用實例
此作業的要求參見:【https://edu.cnblogs.com/campus/nenu/2018fall/homework/2446】
在軟件工程中存在很多原則,在我的代碼作業和非代碼作業中均有體現。
一.首先分析我的代碼作業:
在我的代碼作業中,滿足了一些原則。代碼要滿足用戶的需求,滿足用戶的需求是我們書寫出正確代碼的前提。在完成用戶需求是,我也犯了很多錯誤,沒有按照輸入的要求進行輸入,雖然得到了正確的結果,但這也算不符合用戶需求;在進行結對編程時,要提前制定代碼編寫的代碼規范,然后在進行代碼的編寫;在代碼書寫之后,要進行再次測試,以保證代碼的精準性。
代碼的連接如下:
詞頻統計的代碼地址:https://git.coding.net/sunsss/work.git
代碼如下:
import reclass WF():def __init__(self):self.file_name = input('please input the name of book:')self.mappings = {}self.get_words()self.console_print()self.__init__()def get_words(self):file_tail = '' if '.txt' in self.file_name else '.txt'with open (self.file_name + file_tail, 'r', encoding = 'utf-8') as f:for line in f:for i in re.sub(r'[^\w\s]','', line).replace('\n','').split(' '):if i not in self.mappings:self.mappings[i] = 1else:self.mappings[i] += 1def console_print(self):for k, w in self.mappings.items():print(k, w)print('\ntotal: %swords' % len(self.mappings))WF()?
該代碼沒有完成功能三和功能四,在之后的效能測試中,也沒有辦法完成。
四則運算的代碼地址:https://git.coding.net/sunsss/two.git
代碼如下:
(1)功能1
1 import random 2 ops = ['+','-','*','/'] 3 com = input('>') #用戶輸入 4 cot = 0 #答對的題 5 x = 0 6 while x < 20 : 7 s1 = random.randint(1,10) 8 s2 = random.randint(1,10) 9 s3 = random.randint(1,10) 10 s4 = random.randint(1,10) 11 op1 = random.choice(ops) #隨機運算符 12 op2 = random.choice(ops) 13 op3 = random.choice(ops) 14 while op1 == op2 == op3: 15 op1 = random.choice(ops) #隨機運算符 16 op2 = random.choice(ops) 17 op3 = random.choice(ops) 18 eq = (str(s1)+op1+str(s2)+op2+str(s3)+op3+str(s4)) 19 res = eval(eq) 20 if len(str(res) ) > 5: 21 continue 22 x += 1 23 print(eq) 24 in_res =eval( input('?')) 25 if in_res == res: 26 print('算對啦,你真是個天才!') 27 cot += 1 28 else: 29 print('再想想吧,答案似乎是%s喔!'%res) 30 31 print('你一共答對%s道題,共20道題'%cot)(2)功能2
1 from random import randint 2 from random import choice 3 ops = ['+','-','*','/'] 4 bra = ['(', '', ')'] 5 com = input('>') #用戶輸入 6 cot = 0 #答對的題 7 x = 0 8 while x < 20 : 9 s1 = randint(1,10) 10 s2 = randint(1,10) 11 s3 = randint(1,10) 12 s4 = randint(1,10) 13 op1 = choice(ops) #隨機運算符 14 op2 = choice(ops) 15 op3 = choice(ops) 16 """括號""" 17 bra_1 = ['' , '' ,''] 18 bra_2 = ['' , '' , ''] 19 i = ii =0 20 while (i ==0 and ii ==2) or abs(i-ii)==1 \ 21 or ii < i : 22 i = randint(0,2) 23 ii = randint(0,2) 24 25 bra_1[i] = '('; bra_2[ii]=')' 26 27 while op1 == op2 == op3 : 28 op1 = choice(ops) #隨機運算符 29 op2 = choice(ops) 30 op3 = choice(ops) 31 32 eq = bra_1[0] + str(s1) + op1 + bra_1[1] + str(s2) + \ 33 bra_2[0] + op2 + bra_1[2] + str(s3) + bra_2[1] + op3 \ 34 + str(s4) + bra_2[2] 35 res = eval(eq) 36 if len(str(res) ) > 5: 37 continue 38 x += 1 39 print(eq) 40 in_res =eval( input('?')) 41 if in_res == res: 42 print('算對啦,你真是個天才!') 43 cot += 1 44 else: 45 print('再想想吧,答案似乎是%s喔!'%res) 46 47 print('你一共答對%s道題,共20道題'%cot)(3)功能3
1 from random import randint 2 from random import choice 3 import os 4 ops = ['+','-','*','/'] 5 bra = ['(', '', ')'] 6 com = input('>') #用戶輸入 7 com_list = com.split() 8 while com_list[2].isdigit() == False: 9 print('題目數量必須是正整數') 10 com = input('>') #用戶輸入 11 com_list = com.split() 12 13 def xx(): 14 s1 = randint(1,10) 15 s2 = randint(1,10) 16 s3 = randint(1,10) 17 s4 = randint(1,10) 18 op1 = choice(ops) #隨機運算符 19 op2 = choice(ops) 20 op3 = choice(ops) 21 """括號""" 22 bra_1 = ['' , '' ,''] 23 bra_2 = ['' , '' , ''] 24 i = ii =0 25 while (i ==0 and ii ==2) or abs(i-ii)==1 \ 26 or ii < i : 27 i = randint(0,2) 28 ii = randint(0,2) 29 30 bra_1[i] = '('; bra_2[ii]=')' 31 32 while op1 == op2 == op3 : 33 op1 = choice(ops) #隨機運算符 34 op2 = choice(ops) 35 op3 = choice(ops) 36 37 eq = bra_1[0] + str(s1) + op1 + bra_1[1] + str(s2) + \ 38 bra_2[0] + op2 + bra_1[2] + str(s3) + bra_2[1] + op3 \ 39 + str(s4) + bra_2[2] 40 res = eval(eq) 41 return [eq,res] 42 43 44 45 eq = []; res = [] 46 while len(res) < int(com_list[2]): 47 a = xx() 48 if a[1] in res or len((str(a[1])) ) >6: #結果一樣的直接就不要 49 continue 50 eq.append(a[0]) 51 res.append(a[1]) 52 53 f= open('題目.txt','w') 54 for i in range(len(eq)): 55 print('{0:15}'.format(eq[i]),end = '') 56 print(res[i]) 57 xxx = 17 - len(eq[i]) 58 f.write(str(eq[i]+' '*xxx)) 59 f.write(str(res[i])+'\n') 60 f.close() 61 os.system('題目.txt') #決定是否打開txt(4)功能4
1 import os 2 from random import randint 3 from random import choice 4 from fractions import Fraction 5 ops = ['+','-','*','/'] 6 bra = ['(', '', ')'] 7 com = input('>') #用戶輸入 8 com_list = com.split() 9 while com_list[2].isdigit() == False: 10 print('題目數量必須是正整數') 11 com = input('>') #用戶輸入 12 com_list = com.split() 13 14 def xx(): 15 s1 = randint(1,10) 16 s2 = randint(1,10) 17 s3 = randint(1,10) 18 s4 = randint(1,10) 19 op1 = choice(ops) #隨機運算符 20 op2 = choice(ops) 21 op3 = choice(ops) 22 """括號""" 23 bra_1 = ['' , '' ,''] 24 bra_2 = ['' , '' , ''] 25 i = ii =0 26 while (i ==0 and ii ==2) or abs(i-ii)==1 \ 27 or ii < i : 28 i = randint(0,2) 29 ii = randint(0,2) 30 31 bra_1[i] = '('; bra_2[ii]=')' 32 33 while op1 == op2 == op3 : 34 op1 = choice(ops) #隨機運算符 35 op2 = choice(ops) 36 op3 = choice(ops) 37 38 eq = bra_1[0] + str(s1) + op1 + bra_1[1] + str(s2) + \ 39 bra_2[0] + op2 + bra_1[2] + str(s3) + bra_2[1] + op3 \ 40 + str(s4) + bra_2[2] 41 res = Fraction(eval(eq)) 42 return [eq,res]在這次代碼書寫中,我和我的同學結對完成,我們提出彼此的想法,提出不同的意見,這次編程是我們兩個人都得到了進步。我們在滿足客戶需求的同時,還根據我們的想法對代碼進行了優化。
二.其次分析我的非代碼作業
第一周的博文作業,算是接觸軟件工程的第一課,存在著這樣一項原則,在回答你的優點是什么,你是如何達到今天的進步的問題?我們回答問題時,要給出具體努力的過程,要有能進行衡量標準你的努力。這個原則讓我頗為受用;每周例行報告的書寫,進行一切實時記錄,使我聯想到了git版本控制,這樣做的目的是是是存儲代碼,防止出現意外代碼消失;吉林市兩日游,對事先會發生的情況未雨綢繆,提出兩套及以上的方案來應對。
轉載于:https://www.cnblogs.com/swn321/p/10048659.html
總結
以上是生活随笔為你收集整理的20181127-1附加作业 软件工程原则的应用实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Day15模块(导入,使用)
- 下一篇: Python数据类型——整型、布尔型、列