diff --git a/homework_01_python/1.py b/homework_01_python/1.py new file mode 100644 index 0000000000000000000000000000000000000000..adca6d42b76244e9a820a970a28c05e9b17d4fad --- /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 0000000000000000000000000000000000000000..f4af1795c8ae224571ed74032d4c3c2da320ed52 --- /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 0000000000000000000000000000000000000000..3706d9c5eeb394a9c5234137b79ff8d435fd5b1d --- /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 0000000000000000000000000000000000000000..d2a0b5230e1a6059e28e4e087d4ecfdff622780c --- /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 0000000000000000000000000000000000000000..fc4d4d9bb69b47333fba9088963962d911060557 --- /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 0000000000000000000000000000000000000000..676e7b2d81e5056b3f5799e610bac85b88a9777d --- /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 0000000000000000000000000000000000000000..fd7a5a32363ae12c274f9dabbaad18ff5b9bda74 --- /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 0000000000000000000000000000000000000000..3a879923fec52d24987d029ef8872495235bf183 --- /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 0000000000000000000000000000000000000000..4b31191e186707d4ec1c2ca0a59309ea20714528 --- /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 0000000000000000000000000000000000000000..2b87fe29025ef7fdc375b0ecf97c9c2d700a26a5 --- /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 0000000000000000000000000000000000000000..1796f312e88bad21cc905f1796888d47c8809b23 --- /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 0000000000000000000000000000000000000000..00760212f1c550a7be8a2ae1695f8d6030f2c414 --- /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 0000000000000000000000000000000000000000..c022cede11d4f39b052c7f11b9bc79d7629f02d6 --- /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 0000000000000000000000000000000000000000..97988f676c76393dd18fa75d39924b29d561610e --- /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 0000000000000000000000000000000000000000..4c88c156a7755ee64e2df3ea7297be40c6d3b973 --- /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 diff --git a/name.txt b/name.txt new file mode 100644 index 0000000000000000000000000000000000000000..dee636d04e37f6aa13742e6f152b52d3e89268fc --- /dev/null +++ b/name.txt @@ -0,0 +1,2 @@ +孙旭 +2022100850 \ No newline at end of file