From 6a4680776abf7ac6cc80baca41c6854a47bc9048 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:00:33 +0000 Subject: [PATCH 01/18] homework_01_python Signed-off-by: sunxu --- 1.py | 9 +++++++++ 10.py | 23 +++++++++++++++++++++++ 11.py | 10 ++++++++++ 12.py | 12 ++++++++++++ 13.py | 13 +++++++++++++ 14.py | 14 ++++++++++++++ 15.py | 20 ++++++++++++++++++++ 2.py | 9 +++++++++ 3.py | 12 ++++++++++++ 4.py | 4 ++++ 5.py | 8 ++++++++ 6.py | 18 ++++++++++++++++++ 7.py | 18 ++++++++++++++++++ 8.py | 13 +++++++++++++ 9.py | 16 ++++++++++++++++ 15 files changed, 199 insertions(+) create mode 100644 1.py create mode 100644 10.py create mode 100644 11.py create mode 100644 12.py create mode 100644 13.py create mode 100644 14.py create mode 100644 15.py create mode 100644 2.py create mode 100644 3.py create mode 100644 4.py create mode 100644 5.py create mode 100644 6.py create mode 100644 7.py create mode 100644 8.py create mode 100644 9.py diff --git a/1.py b/1.py new file mode 100644 index 0000000..adca6d4 --- /dev/null +++ b/1.py @@ -0,0 +1,9 @@ +str="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." +str=str.replace(",",'') +str=str.replace(".",'') +word = str.split(' ') +d = dict() +for s in word: + if s!='': + d[s]=d.get(s,0)+1 +print(d) \ No newline at end of file diff --git a/10.py b/10.py new file mode 100644 index 0000000..f4af179 --- /dev/null +++ b/10.py @@ -0,0 +1,23 @@ + +def fun(num,k): + + for i in range(len(num)): + sums=0 + for j in range(i,len(num)): + sums+=int(num[j]) + if sums>=k: + if sums%k==0: + return True + return False + +if __name__ == '__main__': + print("Enter an array:") + #23,2,4,6,7 + #23,2,6,4,7 + input_num = input() + print("Enter an array:") + k = int(input()) + num = input_num.split(",") + + + print(fun(num,k)) \ No newline at end of file diff --git a/11.py b/11.py new file mode 100644 index 0000000..3706d9c --- /dev/null +++ b/11.py @@ -0,0 +1,10 @@ +input_str = input() +d = dict() +for s in input_str: + d[s]=d.get(s,0)+1 + + +if(sum(d.values())>len(d)): + print("False") +else: + print("True") \ No newline at end of file diff --git a/12.py b/12.py new file mode 100644 index 0000000..d2a0b52 --- /dev/null +++ b/12.py @@ -0,0 +1,12 @@ +input_str = input() +dict_letter = dict() +for s in input_str: + dict_letter[s]=dict_letter.get(s,0)+1 + + +b=dict_letter.get('b',0) +a=dict_letter.get('a',0) +l=dict_letter.get('l',0)/2 +o=dict_letter.get('o',0)/2 +n=dict_letter.get('n',0) +print(min(b,a,l,o,n)) \ No newline at end of file diff --git a/13.py b/13.py new file mode 100644 index 0000000..fc4d4d9 --- /dev/null +++ b/13.py @@ -0,0 +1,13 @@ +import random +import string + +activation_code = string.ascii_uppercase + '0123456789' +num=200#激活码数量 +length=11#激活码长度,KR603guyVvR是一个激活码 + +for i in range(num): + code='' + for j in range(length): + + code += random.choice(activation_code) + print(code) \ No newline at end of file diff --git a/14.py b/14.py new file mode 100644 index 0000000..676e7b2 --- /dev/null +++ b/14.py @@ -0,0 +1,14 @@ +import os +path ='/mnt/sunxu/code/machinelearning_homework/homework_01_python' + +name = [] +''' +root所指的是当前正在遍历的这个文件夹的本身的地址 +dirs是一个list内容是该文件夹中所有的目录的名字(不包括子目录) +files是list ,内容是该文件夹中所有的文件(不包括子目录) +''' +for root,dirs,files in os.walk(path): + for i in files: + if os.path.splitext(i)[1]=='.py': + name.append(i) +print(name) \ No newline at end of file diff --git a/15.py b/15.py new file mode 100644 index 0000000..fd7a5a3 --- /dev/null +++ b/15.py @@ -0,0 +1,20 @@ +import os +path='/mnt/sunxu/code/machinelearning_homework/homework_01_python' +count_py = 0 +count_md = 0 + +for root,dirs,files in os.walk(path): + for i in files: + + if os.path.splitext(i)[1]=='.py': + for count, line in enumerate(open(i, 'r', encoding='utf-8').readlines()): + count+=1 + count_py+=count + + if os.path.splitext(i)[1]=='.md': + for count, line in enumerate(open(i, 'r', encoding='utf-8').readlines()): + count+=1 + count_md+=count + +print('py:%d'%(count_py)) +print('md:%d'%(count_md)) \ No newline at end of file diff --git a/2.py b/2.py new file mode 100644 index 0000000..3a87992 --- /dev/null +++ b/2.py @@ -0,0 +1,9 @@ +a=[1,2,3,4] +count=0 +for i in a: + for j in a: + for k in a: + if i!=k and j!=k and i!=j: + print(i,j,k) + count+=1 +print(count) \ No newline at end of file diff --git a/3.py b/3.py new file mode 100644 index 0000000..4b31191 --- /dev/null +++ b/3.py @@ -0,0 +1,12 @@ +money= int(input()) +profit = [1000000,600000,400000,200000,100000,0] +commission = [0.01,0.015,0.03,0.05,0.075,0.1] +result = 0 + + +for i in range(6): + + if money > profit[i]: + result += (money-profit[i])*commission[i] + money = profit[i] +print(result) diff --git a/4.py b/4.py new file mode 100644 index 0000000..2b87fe2 --- /dev/null +++ b/4.py @@ -0,0 +1,4 @@ +for i in range(1,9): + for j in range(1,i+1): + print('{}x{}={}\t'.format(i,j,i*j),end="") + print('\n') \ No newline at end of file diff --git a/5.py b/5.py new file mode 100644 index 0000000..1796f31 --- /dev/null +++ b/5.py @@ -0,0 +1,8 @@ +a=2 +sum=0 +i=0 +while(a<=100): + sum += pow(-1,i)*a + a=a+1 + i=i+1 +print(sum) \ No newline at end of file diff --git a/6.py b/6.py new file mode 100644 index 0000000..0076021 --- /dev/null +++ b/6.py @@ -0,0 +1,18 @@ +list=[1, 10, 4, 2, 9, 2, 34, 5, 9, 8, 5, 0] +index = range(12) +copy=list[:] + +for i in range(len(list)): + for j in range(i+1,len(list)): + if list[i]>list[j]: + temp=list[i] + list[i]=list[j] + list[j]=temp +print(list) + +indexlist=[] +for a in list: + num = copy.index(a) + copy[num]=-1 + indexlist.append(num) +print(indexlist) \ No newline at end of file diff --git a/7.py b/7.py new file mode 100644 index 0000000..c022ced --- /dev/null +++ b/7.py @@ -0,0 +1,18 @@ +import numpy as np +import sys +print("target:") +target = int(input()) +a = np.array([ +[1, 4, 7, 11, 15], +[2, 5, 8, 12, 19], +[3, 6, 9, 16, 22], +[10, 13, 14, 17, 24], +[18, 21, 23, 26, 30] +]) + +for i in range(a.shape[0]): + for j in range(a.shape[1]): + if a[i][j]==target: + print("True") + sys.exit(0) +print("False") \ No newline at end of file diff --git a/8.py b/8.py new file mode 100644 index 0000000..97988f6 --- /dev/null +++ b/8.py @@ -0,0 +1,13 @@ + +def factor(num): + s=set() + for i in range(1,num): + if num%i==0: + s.add(i) + s.add(num/i) + return s + +if __name__ =='__main__': + for i in range(2,1000): + if 2*i == sum(factor(i)): + print(i) \ No newline at end of file diff --git a/9.py b/9.py new file mode 100644 index 0000000..4c88c15 --- /dev/null +++ b/9.py @@ -0,0 +1,16 @@ +def isone(n): + sum=0 + for i in range(len(n)): + sum += pow(int(n[i]),2) + n=sum + if n==1: + return True + elif len(str(n))==1 and n!=1: + return False + else: + return isone(str(n)) + +if __name__ == '__main__': + print("n:") + n = input() + print(isone(n)) \ No newline at end of file -- Gitee From cb24738b10d51e908b238d044f11dada9b3e23f8 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:01:28 +0000 Subject: [PATCH 02/18] homework_01_python Signed-off-by: sunxu --- homework_01_python/1.py | 9 +++++++++ homework_01_python/10.py | 23 +++++++++++++++++++++++ homework_01_python/11.py | 10 ++++++++++ homework_01_python/12.py | 12 ++++++++++++ homework_01_python/13.py | 13 +++++++++++++ homework_01_python/14.py | 14 ++++++++++++++ homework_01_python/15.py | 20 ++++++++++++++++++++ homework_01_python/2.py | 9 +++++++++ homework_01_python/3.py | 12 ++++++++++++ homework_01_python/4.py | 4 ++++ homework_01_python/5.py | 8 ++++++++ homework_01_python/6.py | 18 ++++++++++++++++++ homework_01_python/7.py | 18 ++++++++++++++++++ homework_01_python/8.py | 13 +++++++++++++ homework_01_python/9.py | 16 ++++++++++++++++ 15 files changed, 199 insertions(+) create mode 100644 homework_01_python/1.py create mode 100644 homework_01_python/10.py create mode 100644 homework_01_python/11.py create mode 100644 homework_01_python/12.py create mode 100644 homework_01_python/13.py create mode 100644 homework_01_python/14.py create mode 100644 homework_01_python/15.py create mode 100644 homework_01_python/2.py create mode 100644 homework_01_python/3.py create mode 100644 homework_01_python/4.py create mode 100644 homework_01_python/5.py create mode 100644 homework_01_python/6.py create mode 100644 homework_01_python/7.py create mode 100644 homework_01_python/8.py create mode 100644 homework_01_python/9.py diff --git a/homework_01_python/1.py b/homework_01_python/1.py new file mode 100644 index 0000000..adca6d4 --- /dev/null +++ b/homework_01_python/1.py @@ -0,0 +1,9 @@ +str="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." +str=str.replace(",",'') +str=str.replace(".",'') +word = str.split(' ') +d = dict() +for s in word: + if s!='': + d[s]=d.get(s,0)+1 +print(d) \ No newline at end of file diff --git a/homework_01_python/10.py b/homework_01_python/10.py new file mode 100644 index 0000000..f4af179 --- /dev/null +++ b/homework_01_python/10.py @@ -0,0 +1,23 @@ + +def fun(num,k): + + for i in range(len(num)): + sums=0 + for j in range(i,len(num)): + sums+=int(num[j]) + if sums>=k: + if sums%k==0: + return True + return False + +if __name__ == '__main__': + print("Enter an array:") + #23,2,4,6,7 + #23,2,6,4,7 + input_num = input() + print("Enter an array:") + k = int(input()) + num = input_num.split(",") + + + print(fun(num,k)) \ No newline at end of file diff --git a/homework_01_python/11.py b/homework_01_python/11.py new file mode 100644 index 0000000..3706d9c --- /dev/null +++ b/homework_01_python/11.py @@ -0,0 +1,10 @@ +input_str = input() +d = dict() +for s in input_str: + d[s]=d.get(s,0)+1 + + +if(sum(d.values())>len(d)): + print("False") +else: + print("True") \ No newline at end of file diff --git a/homework_01_python/12.py b/homework_01_python/12.py new file mode 100644 index 0000000..d2a0b52 --- /dev/null +++ b/homework_01_python/12.py @@ -0,0 +1,12 @@ +input_str = input() +dict_letter = dict() +for s in input_str: + dict_letter[s]=dict_letter.get(s,0)+1 + + +b=dict_letter.get('b',0) +a=dict_letter.get('a',0) +l=dict_letter.get('l',0)/2 +o=dict_letter.get('o',0)/2 +n=dict_letter.get('n',0) +print(min(b,a,l,o,n)) \ No newline at end of file diff --git a/homework_01_python/13.py b/homework_01_python/13.py new file mode 100644 index 0000000..fc4d4d9 --- /dev/null +++ b/homework_01_python/13.py @@ -0,0 +1,13 @@ +import random +import string + +activation_code = string.ascii_uppercase + '0123456789' +num=200#激活码数量 +length=11#激活码长度,KR603guyVvR是一个激活码 + +for i in range(num): + code='' + for j in range(length): + + code += random.choice(activation_code) + print(code) \ No newline at end of file diff --git a/homework_01_python/14.py b/homework_01_python/14.py new file mode 100644 index 0000000..676e7b2 --- /dev/null +++ b/homework_01_python/14.py @@ -0,0 +1,14 @@ +import os +path ='/mnt/sunxu/code/machinelearning_homework/homework_01_python' + +name = [] +''' +root所指的是当前正在遍历的这个文件夹的本身的地址 +dirs是一个list内容是该文件夹中所有的目录的名字(不包括子目录) +files是list ,内容是该文件夹中所有的文件(不包括子目录) +''' +for root,dirs,files in os.walk(path): + for i in files: + if os.path.splitext(i)[1]=='.py': + name.append(i) +print(name) \ No newline at end of file diff --git a/homework_01_python/15.py b/homework_01_python/15.py new file mode 100644 index 0000000..fd7a5a3 --- /dev/null +++ b/homework_01_python/15.py @@ -0,0 +1,20 @@ +import os +path='/mnt/sunxu/code/machinelearning_homework/homework_01_python' +count_py = 0 +count_md = 0 + +for root,dirs,files in os.walk(path): + for i in files: + + if os.path.splitext(i)[1]=='.py': + for count, line in enumerate(open(i, 'r', encoding='utf-8').readlines()): + count+=1 + count_py+=count + + if os.path.splitext(i)[1]=='.md': + for count, line in enumerate(open(i, 'r', encoding='utf-8').readlines()): + count+=1 + count_md+=count + +print('py:%d'%(count_py)) +print('md:%d'%(count_md)) \ No newline at end of file diff --git a/homework_01_python/2.py b/homework_01_python/2.py new file mode 100644 index 0000000..3a87992 --- /dev/null +++ b/homework_01_python/2.py @@ -0,0 +1,9 @@ +a=[1,2,3,4] +count=0 +for i in a: + for j in a: + for k in a: + if i!=k and j!=k and i!=j: + print(i,j,k) + count+=1 +print(count) \ No newline at end of file diff --git a/homework_01_python/3.py b/homework_01_python/3.py new file mode 100644 index 0000000..4b31191 --- /dev/null +++ b/homework_01_python/3.py @@ -0,0 +1,12 @@ +money= int(input()) +profit = [1000000,600000,400000,200000,100000,0] +commission = [0.01,0.015,0.03,0.05,0.075,0.1] +result = 0 + + +for i in range(6): + + if money > profit[i]: + result += (money-profit[i])*commission[i] + money = profit[i] +print(result) diff --git a/homework_01_python/4.py b/homework_01_python/4.py new file mode 100644 index 0000000..2b87fe2 --- /dev/null +++ b/homework_01_python/4.py @@ -0,0 +1,4 @@ +for i in range(1,9): + for j in range(1,i+1): + print('{}x{}={}\t'.format(i,j,i*j),end="") + print('\n') \ No newline at end of file diff --git a/homework_01_python/5.py b/homework_01_python/5.py new file mode 100644 index 0000000..1796f31 --- /dev/null +++ b/homework_01_python/5.py @@ -0,0 +1,8 @@ +a=2 +sum=0 +i=0 +while(a<=100): + sum += pow(-1,i)*a + a=a+1 + i=i+1 +print(sum) \ No newline at end of file diff --git a/homework_01_python/6.py b/homework_01_python/6.py new file mode 100644 index 0000000..0076021 --- /dev/null +++ b/homework_01_python/6.py @@ -0,0 +1,18 @@ +list=[1, 10, 4, 2, 9, 2, 34, 5, 9, 8, 5, 0] +index = range(12) +copy=list[:] + +for i in range(len(list)): + for j in range(i+1,len(list)): + if list[i]>list[j]: + temp=list[i] + list[i]=list[j] + list[j]=temp +print(list) + +indexlist=[] +for a in list: + num = copy.index(a) + copy[num]=-1 + indexlist.append(num) +print(indexlist) \ No newline at end of file diff --git a/homework_01_python/7.py b/homework_01_python/7.py new file mode 100644 index 0000000..c022ced --- /dev/null +++ b/homework_01_python/7.py @@ -0,0 +1,18 @@ +import numpy as np +import sys +print("target:") +target = int(input()) +a = np.array([ +[1, 4, 7, 11, 15], +[2, 5, 8, 12, 19], +[3, 6, 9, 16, 22], +[10, 13, 14, 17, 24], +[18, 21, 23, 26, 30] +]) + +for i in range(a.shape[0]): + for j in range(a.shape[1]): + if a[i][j]==target: + print("True") + sys.exit(0) +print("False") \ No newline at end of file diff --git a/homework_01_python/8.py b/homework_01_python/8.py new file mode 100644 index 0000000..97988f6 --- /dev/null +++ b/homework_01_python/8.py @@ -0,0 +1,13 @@ + +def factor(num): + s=set() + for i in range(1,num): + if num%i==0: + s.add(i) + s.add(num/i) + return s + +if __name__ =='__main__': + for i in range(2,1000): + if 2*i == sum(factor(i)): + print(i) \ No newline at end of file diff --git a/homework_01_python/9.py b/homework_01_python/9.py new file mode 100644 index 0000000..4c88c15 --- /dev/null +++ b/homework_01_python/9.py @@ -0,0 +1,16 @@ +def isone(n): + sum=0 + for i in range(len(n)): + sum += pow(int(n[i]),2) + n=sum + if n==1: + return True + elif len(str(n))==1 and n!=1: + return False + else: + return isone(str(n)) + +if __name__ == '__main__': + print("n:") + n = input() + print(isone(n)) \ No newline at end of file -- Gitee From 38b7e520415b24e32f8f562c8b9d37f7ce4a6bdf Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:01:53 +0000 Subject: [PATCH 03/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=201.?= =?UTF-8?q?py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.py | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 1.py diff --git a/1.py b/1.py deleted file mode 100644 index adca6d4..0000000 --- a/1.py +++ /dev/null @@ -1,9 +0,0 @@ -str="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." -str=str.replace(",",'') -str=str.replace(".",'') -word = str.split(' ') -d = dict() -for s in word: - if s!='': - d[s]=d.get(s,0)+1 -print(d) \ No newline at end of file -- Gitee From ab72acd882b8c857d5ae935e7170a957b37ebc96 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:02:03 +0000 Subject: [PATCH 04/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2010?= =?UTF-8?q?.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 10.py | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 10.py diff --git a/10.py b/10.py deleted file mode 100644 index f4af179..0000000 --- a/10.py +++ /dev/null @@ -1,23 +0,0 @@ - -def fun(num,k): - - for i in range(len(num)): - sums=0 - for j in range(i,len(num)): - sums+=int(num[j]) - if sums>=k: - if sums%k==0: - return True - return False - -if __name__ == '__main__': - print("Enter an array:") - #23,2,4,6,7 - #23,2,6,4,7 - input_num = input() - print("Enter an array:") - k = int(input()) - num = input_num.split(",") - - - print(fun(num,k)) \ No newline at end of file -- Gitee From 513deaaaba9c7f2f172b574cd9b264792d0c3605 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:02:22 +0000 Subject: [PATCH 05/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=205.?= =?UTF-8?q?py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 5.py | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 5.py diff --git a/5.py b/5.py deleted file mode 100644 index 1796f31..0000000 --- a/5.py +++ /dev/null @@ -1,8 +0,0 @@ -a=2 -sum=0 -i=0 -while(a<=100): - sum += pow(-1,i)*a - a=a+1 - i=i+1 -print(sum) \ No newline at end of file -- Gitee From a01b0bd09a7f694af8c1a279aaef739e9884a720 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:02:42 +0000 Subject: [PATCH 06/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=207.?= =?UTF-8?q?py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 7.py | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 7.py diff --git a/7.py b/7.py deleted file mode 100644 index c022ced..0000000 --- a/7.py +++ /dev/null @@ -1,18 +0,0 @@ -import numpy as np -import sys -print("target:") -target = int(input()) -a = np.array([ -[1, 4, 7, 11, 15], -[2, 5, 8, 12, 19], -[3, 6, 9, 16, 22], -[10, 13, 14, 17, 24], -[18, 21, 23, 26, 30] -]) - -for i in range(a.shape[0]): - for j in range(a.shape[1]): - if a[i][j]==target: - print("True") - sys.exit(0) -print("False") \ No newline at end of file -- Gitee From 3d375d5c28a6a30fed90059051971e2eb8aec486 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:02:51 +0000 Subject: [PATCH 07/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2013?= =?UTF-8?q?.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 13.py | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 13.py diff --git a/13.py b/13.py deleted file mode 100644 index fc4d4d9..0000000 --- a/13.py +++ /dev/null @@ -1,13 +0,0 @@ -import random -import string - -activation_code = string.ascii_uppercase + '0123456789' -num=200#激活码数量 -length=11#激活码长度,KR603guyVvR是一个激活码 - -for i in range(num): - code='' - for j in range(length): - - code += random.choice(activation_code) - print(code) \ No newline at end of file -- Gitee From 6d8b8fbe97143612db67133d51635a3e6cf9da6b Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:03:11 +0000 Subject: [PATCH 08/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2015?= =?UTF-8?q?.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 15.py | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 15.py diff --git a/15.py b/15.py deleted file mode 100644 index fd7a5a3..0000000 --- a/15.py +++ /dev/null @@ -1,20 +0,0 @@ -import os -path='/mnt/sunxu/code/machinelearning_homework/homework_01_python' -count_py = 0 -count_md = 0 - -for root,dirs,files in os.walk(path): - for i in files: - - if os.path.splitext(i)[1]=='.py': - for count, line in enumerate(open(i, 'r', encoding='utf-8').readlines()): - count+=1 - count_py+=count - - if os.path.splitext(i)[1]=='.md': - for count, line in enumerate(open(i, 'r', encoding='utf-8').readlines()): - count+=1 - count_md+=count - -print('py:%d'%(count_py)) -print('md:%d'%(count_md)) \ No newline at end of file -- Gitee From 4df0ce081d9bc7591072327aa3eb7bf33e593e85 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:03:50 +0000 Subject: [PATCH 09/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=203.?= =?UTF-8?q?py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 3.py | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 3.py diff --git a/3.py b/3.py deleted file mode 100644 index 4b31191..0000000 --- a/3.py +++ /dev/null @@ -1,12 +0,0 @@ -money= int(input()) -profit = [1000000,600000,400000,200000,100000,0] -commission = [0.01,0.015,0.03,0.05,0.075,0.1] -result = 0 - - -for i in range(6): - - if money > profit[i]: - result += (money-profit[i])*commission[i] - money = profit[i] -print(result) -- Gitee From f77212893e74ca4a874afbc8dba3d08d1a0568ae Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:04:22 +0000 Subject: [PATCH 10/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2011?= =?UTF-8?q?.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 11.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 11.py diff --git a/11.py b/11.py deleted file mode 100644 index 3706d9c..0000000 --- a/11.py +++ /dev/null @@ -1,10 +0,0 @@ -input_str = input() -d = dict() -for s in input_str: - d[s]=d.get(s,0)+1 - - -if(sum(d.values())>len(d)): - print("False") -else: - print("True") \ No newline at end of file -- Gitee From a9bbefdb95c3bc37d874048c5a9c3e09cae96f0d Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:04:31 +0000 Subject: [PATCH 11/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=202.?= =?UTF-8?q?py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 2.py | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 2.py diff --git a/2.py b/2.py deleted file mode 100644 index 3a87992..0000000 --- a/2.py +++ /dev/null @@ -1,9 +0,0 @@ -a=[1,2,3,4] -count=0 -for i in a: - for j in a: - for k in a: - if i!=k and j!=k and i!=j: - print(i,j,k) - count+=1 -print(count) \ No newline at end of file -- Gitee From 7c622c46fbd16a4caa960ae077482181becdfca0 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:04:41 +0000 Subject: [PATCH 12/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2014?= =?UTF-8?q?.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 14.py | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 14.py diff --git a/14.py b/14.py deleted file mode 100644 index 676e7b2..0000000 --- a/14.py +++ /dev/null @@ -1,14 +0,0 @@ -import os -path ='/mnt/sunxu/code/machinelearning_homework/homework_01_python' - -name = [] -''' -root所指的是当前正在遍历的这个文件夹的本身的地址 -dirs是一个list内容是该文件夹中所有的目录的名字(不包括子目录) -files是list ,内容是该文件夹中所有的文件(不包括子目录) -''' -for root,dirs,files in os.walk(path): - for i in files: - if os.path.splitext(i)[1]=='.py': - name.append(i) -print(name) \ No newline at end of file -- Gitee From 64c13fcab39900ed305aa3d38cce6dfe7fc30b06 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:04:50 +0000 Subject: [PATCH 13/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=206.?= =?UTF-8?q?py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 6.py | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 6.py diff --git a/6.py b/6.py deleted file mode 100644 index 0076021..0000000 --- a/6.py +++ /dev/null @@ -1,18 +0,0 @@ -list=[1, 10, 4, 2, 9, 2, 34, 5, 9, 8, 5, 0] -index = range(12) -copy=list[:] - -for i in range(len(list)): - for j in range(i+1,len(list)): - if list[i]>list[j]: - temp=list[i] - list[i]=list[j] - list[j]=temp -print(list) - -indexlist=[] -for a in list: - num = copy.index(a) - copy[num]=-1 - indexlist.append(num) -print(indexlist) \ No newline at end of file -- Gitee From 3d70c6ce12ae6afff8184d0a21bc439964aafb57 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:04:59 +0000 Subject: [PATCH 14/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=204.?= =?UTF-8?q?py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4.py | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 4.py diff --git a/4.py b/4.py deleted file mode 100644 index 2b87fe2..0000000 --- a/4.py +++ /dev/null @@ -1,4 +0,0 @@ -for i in range(1,9): - for j in range(1,i+1): - print('{}x{}={}\t'.format(i,j,i*j),end="") - print('\n') \ No newline at end of file -- Gitee From 075f5d8faddd4a216a02807578ba4c6fc7545216 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:05:42 +0000 Subject: [PATCH 15/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=2012?= =?UTF-8?q?.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 12.py | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 12.py diff --git a/12.py b/12.py deleted file mode 100644 index d2a0b52..0000000 --- a/12.py +++ /dev/null @@ -1,12 +0,0 @@ -input_str = input() -dict_letter = dict() -for s in input_str: - dict_letter[s]=dict_letter.get(s,0)+1 - - -b=dict_letter.get('b',0) -a=dict_letter.get('a',0) -l=dict_letter.get('l',0)/2 -o=dict_letter.get('o',0)/2 -n=dict_letter.get('n',0) -print(min(b,a,l,o,n)) \ No newline at end of file -- Gitee From c9cdc41252e8781a3ae0200c254e41bd5098a5c2 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:05:52 +0000 Subject: [PATCH 16/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=208.?= =?UTF-8?q?py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 8.py | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 8.py diff --git a/8.py b/8.py deleted file mode 100644 index 97988f6..0000000 --- a/8.py +++ /dev/null @@ -1,13 +0,0 @@ - -def factor(num): - s=set() - for i in range(1,num): - if num%i==0: - s.add(i) - s.add(num/i) - return s - -if __name__ =='__main__': - for i in range(2,1000): - if 2*i == sum(factor(i)): - print(i) \ No newline at end of file -- Gitee From a0d1a211e560e07c925b202ec0e0f45ad4635637 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:06:04 +0000 Subject: [PATCH 17/18] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=209.?= =?UTF-8?q?py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 9.py | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 9.py diff --git a/9.py b/9.py deleted file mode 100644 index 4c88c15..0000000 --- a/9.py +++ /dev/null @@ -1,16 +0,0 @@ -def isone(n): - sum=0 - for i in range(len(n)): - sum += pow(int(n[i]),2) - n=sum - if n==1: - return True - elif len(str(n))==1 and n!=1: - return False - else: - return isone(str(n)) - -if __name__ == '__main__': - print("n:") - n = input() - print(isone(n)) \ No newline at end of file -- Gitee From 53591d49d743f82586caf8a387c9af08a7920d97 Mon Sep 17 00:00:00 2001 From: sunxu Date: Sat, 19 Nov 2022 13:08:21 +0000 Subject: [PATCH 18/18] =?UTF-8?q?=E5=AD=99=E6=97=AD2022100850?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunxu --- name.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 name.txt diff --git a/name.txt b/name.txt new file mode 100644 index 0000000..dee636d --- /dev/null +++ b/name.txt @@ -0,0 +1,2 @@ +孙旭 +2022100850 \ No newline at end of file -- Gitee