From b18e95114b85b74713cd91a6865a9e4b527716d7 Mon Sep 17 00:00:00 2001 From: Tonghui Miao <1658576025@qq.com> Date: Fri, 9 Oct 2020 17:05:07 +0800 Subject: [PATCH 1/2] finsh the first homework --- homework_01_python/hw1.py.txt | 22 ++++++++++++++++++++++ homework_01_python/hw10.py.txt | 19 +++++++++++++++++++ homework_01_python/hw2.py.txt | 19 +++++++++++++++++++ homework_01_python/hw3.py.txt | 28 ++++++++++++++++++++++++++++ homework_01_python/hw4.py.txt | 14 ++++++++++++++ homework_01_python/hw5.py.txt | 12 ++++++++++++ homework_01_python/hw6.py.txt | 20 ++++++++++++++++++++ homework_01_python/hw7.py.txt | 11 +++++++++++ homework_01_python/hw8.py.txt | 30 ++++++++++++++++++++++++++++++ homework_01_python/hw9.py.txt | 21 +++++++++++++++++++++ 10 files changed, 196 insertions(+) create mode 100644 homework_01_python/hw1.py.txt create mode 100644 homework_01_python/hw10.py.txt create mode 100644 homework_01_python/hw2.py.txt create mode 100644 homework_01_python/hw3.py.txt create mode 100644 homework_01_python/hw4.py.txt create mode 100644 homework_01_python/hw5.py.txt create mode 100644 homework_01_python/hw6.py.txt create mode 100644 homework_01_python/hw7.py.txt create mode 100644 homework_01_python/hw8.py.txt create mode 100644 homework_01_python/hw9.py.txt diff --git a/homework_01_python/hw1.py.txt b/homework_01_python/hw1.py.txt new file mode 100644 index 0000000..fc14887 --- /dev/null +++ b/homework_01_python/hw1.py.txt @@ -0,0 +1,22 @@ +代码: +sentence = 'One is always on a strange road, watching strange scenery and listening to strange music. Then one day, you will find that the things you try hard to forget are already gone. ' +#读入字符串 +list1 = sentence.split() +#将字符串分割成单个单词的列表 + +set1 = set(list1) +list2 = list(set1) +#将列表转换为集合再转换为列表 + +dir1 = {} +for x in range(len(list2)): + dir1[list2[x]] = 0 + for y in range(len(list1)): + if list2[x] == list1[y]: + dir1[list2[x]] += 1 + +print (dir1) + + +结果: +{'one': 1, 'is': 1, 'on': 1, 'try': 1, 'will': 1, 'listening': 1, 'One': 1, 'watching': 1, 'a': 1, 'already': 1, 'strange': 3, 'day,': 1, 'and': 1, 'gone.': 1, 'music.': 1, 'to': 2, 'things': 1, 'scenery': 1, 'you': 2, 'always': 1, 'road,': 1, 'hard': 1, 'that': 1, 'the': 1, 'forget': 1, 'Then': 1, 'find': 1, 'are': 1} diff --git a/homework_01_python/hw10.py.txt b/homework_01_python/hw10.py.txt new file mode 100644 index 0000000..e9cd068 --- /dev/null +++ b/homework_01_python/hw10.py.txt @@ -0,0 +1,19 @@ +import os +# 计算代码行 +for i in os.listdir('.'): # 打开本地目录的文件 + if os.path.splitext(i)[1] == '.py': + with open(i, 'rb') as f: + code = 0 # 计算代码行 + notes = -1 # 计算注释行 + empty_line = 0 # 计算空白行 + for j in f.readlines(): + code += 1 + if len(j.strip()) == 0: + empty_line += 1 + if b'#' in j: + notes += 1 + print('代码总行数:', code) + print('空白行总行数', empty_line) + if notes == -1: + notes = 0 + print('注释行总行数', notes) \ No newline at end of file diff --git a/homework_01_python/hw2.py.txt b/homework_01_python/hw2.py.txt new file mode 100644 index 0000000..85f659e --- /dev/null +++ b/homework_01_python/hw2.py.txt @@ -0,0 +1,19 @@ +代码: +List = (1,2,3,4) +Count = 0 +for i in range(len(List)) : + for j in range(len(List)) : + for k in range(len(List)) : + if ( List[i] != List[j] and List[j] != List[k] and List[k] != List[i]) : + print('%d%d%d' % (List[i],List[j],List[k]), end=' ') + Count = Count + 1 + if (Count % 10 == 0) : + print('\n') + print('count=',Count) + +结果: +123 124 132 134 142 143 213 214 231 234 + +241 243 312 314 321 324 341 342 412 413 + +421 423 431 432 count= 24 \ No newline at end of file diff --git a/homework_01_python/hw3.py.txt b/homework_01_python/hw3.py.txt new file mode 100644 index 0000000..67a5621 --- /dev/null +++ b/homework_01_python/hw3.py.txt @@ -0,0 +1,28 @@ +代码: +def commission(I): + if I>0 and I<=100000: + bonus = I*0.1 + print(bonus) + elif I>100000 and I<=200000: + bonus = 100000*0.1 + (I-100000)*0.075 + print(bonus) + elif I>200000 and I<=400000: + bonus = 100000*0.1 + 100000*0.075 + (I-200000)*0.05 + print(bonus) + elif I>400000 and I<=600000: + bonus = 100000*0.1 + 100000*0.075 + 200000*0.05 + (I-400000)*0.03 + print(bonus) + elif I>600000 and I<=1000000: + bonus = 100000*0.1 + 100000*0.075 + 200000*0.05 + 200000*0.03 + (I-600000)*0.015 + print(bonus) + elif I>1000000: + bonus = 100000*0.1 + 100000*0.075 + 200000*0.05 + 200000*0.03 + 400000*0.015 + (I-600000)*0.01 + print(bonus) + +def main(): + I = 1 + while I != 0: + I = int(input('请输入利润I')) + commission(I) + +main() diff --git a/homework_01_python/hw4.py.txt b/homework_01_python/hw4.py.txt new file mode 100644 index 0000000..c41aa37 --- /dev/null +++ b/homework_01_python/hw4.py.txt @@ -0,0 +1,14 @@ +for i in range(1,10): + for j in range(1,i+1): + print('%s*%s=%s' %(i,j,i*j),end = ' ') + print() + +1*1=1 +2*1=2 2*2=4 +3*1=3 3*2=6 3*3=9 +4*1=4 4*2=8 4*3=12 4*4=16 +5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 +6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 +7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 +8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 +9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81 \ No newline at end of file diff --git a/homework_01_python/hw5.py.txt b/homework_01_python/hw5.py.txt new file mode 100644 index 0000000..74ae0fa --- /dev/null +++ b/homework_01_python/hw5.py.txt @@ -0,0 +1,12 @@ +代码: +i,sum = 2,0 +while i <= 100: + if i % 2 == 0: + sum = sum + i #偶数项加 + else: + sum = sum - i #奇数项减 + i += 1 +print(sum) + + +结果:51 \ No newline at end of file diff --git a/homework_01_python/hw6.py.txt b/homework_01_python/hw6.py.txt new file mode 100644 index 0000000..bff82ab --- /dev/null +++ b/homework_01_python/hw6.py.txt @@ -0,0 +1,20 @@ +list1=[1, 10, 4, 2, 9, 2, 34, 5, 9, 8, 5, 0] +list2=[] +for j in range(10,1,-1): + + smallest=list1[0] + for i in range(1,j): + + if smallest<=list1[i]: + pass + else: + smallest=list1[i] + + list1.remove(smallest) + list2.append(smallest) +list2.append(list1[0]) +print(list2) + + +结果: +[1, 2, 2, 4, 5, 8, 9, 9, 10, 34] \ No newline at end of file diff --git a/homework_01_python/hw7.py.txt b/homework_01_python/hw7.py.txt new file mode 100644 index 0000000..01dc607 --- /dev/null +++ b/homework_01_python/hw7.py.txt @@ -0,0 +1,11 @@ +def searchMatrix(self, matrix, target): + if(matrix==[]or matrix==[[]]):return False + for i in range(0,len(matrix)): + if(target<=matrix[i][-1] and target>=matrix[i][0]):return target in matrix[i] + if target Date: Sun, 18 Oct 2020 10:03:24 +0800 Subject: [PATCH 2/2] improve some descriptions --- Homework2/1.1.py.txt | 3 +++ Homework2/1.2.py.txt | 2 ++ Homework2/1.3.py.txt | 4 ++++ Homework2/1.4.py.txt | 8 ++++++++ Homework2/1.5.py.txt | 3 +++ Homework2/1.6.py.txt | 7 +++++++ 6 files changed, 27 insertions(+) create mode 100644 Homework2/1.1.py.txt create mode 100644 Homework2/1.2.py.txt create mode 100644 Homework2/1.3.py.txt create mode 100644 Homework2/1.4.py.txt create mode 100644 Homework2/1.5.py.txt create mode 100644 Homework2/1.6.py.txt diff --git a/Homework2/1.1.py.txt b/Homework2/1.1.py.txt new file mode 100644 index 0000000..828de25 --- /dev/null +++ b/Homework2/1.1.py.txt @@ -0,0 +1,3 @@ +Z = np.ones((5,5)) +Z = np.pad(Z, pad_width=1, mode='constant', constant_values=0) +print(Z) \ No newline at end of file diff --git a/Homework2/1.2.py.txt b/Homework2/1.2.py.txt new file mode 100644 index 0000000..e1253e9 --- /dev/null +++ b/Homework2/1.2.py.txt @@ -0,0 +1,2 @@ +Z = np.diag(1+np.arange(4),k=-1) +print(Z) \ No newline at end of file diff --git a/Homework2/1.3.py.txt b/Homework2/1.3.py.txt new file mode 100644 index 0000000..0feecac --- /dev/null +++ b/Homework2/1.3.py.txt @@ -0,0 +1,4 @@ +Z = np.zeros((8, 8), dtype=int) +Z[1::2, ::2] = 1 +Z[::2, 1::2] = 1 +print (Z) \ No newline at end of file diff --git a/Homework2/1.4.py.txt b/Homework2/1.4.py.txt new file mode 100644 index 0000000..6a94123 --- /dev/null +++ b/Homework2/1.4.py.txt @@ -0,0 +1,8 @@ +In [1]: import numpy as np + ...: A = np.mat('1,2; 4,5') # 构造系数矩阵 A + ...: b = np.mat('3,6').T # 构造转置矩阵 b + ...: r = np.linalg.solve(A,b) # 调用 solve 函数求解 + ...: print r + ...: +Out[1]: [[-1.] + [ 2.]] diff --git a/Homework2/1.5.py.txt b/Homework2/1.5.py.txt new file mode 100644 index 0000000..38ed98c --- /dev/null +++ b/Homework2/1.5.py.txt @@ -0,0 +1,3 @@ +a=[1,2,3,4,5] +a = a[::-1] +print(a) \ No newline at end of file diff --git a/Homework2/1.6.py.txt b/Homework2/1.6.py.txt new file mode 100644 index 0000000..ede2316 --- /dev/null +++ b/Homework2/1.6.py.txt @@ -0,0 +1,7 @@ +import numpy as np +a = np.random.randint(0,100,size=[10,10]) +print (a) +min=np.min(a) +max=np.max(a) +print(min) +print(max) \ No newline at end of file -- Gitee