diff --git a/homework_01_python/homework_python1.py b/homework_01_python/homework_python1.py new file mode 100644 index 0000000000000000000000000000000000000000..06bb05dbe295b68e1b3dc6ca6878d3575d9bcaf8 --- /dev/null +++ b/homework_01_python/homework_python1.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Nov 14 19:38:35 2022 + +@author: Zuo zijun +""" +list1="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. " +dict={} +keys=list1.split() +for key in keys: + if key in dict.keys(): + dict[key]+=1 + else: + dict[key]=1 +print(dict) \ No newline at end of file diff --git a/homework_01_python/homework_python10.py b/homework_01_python/homework_python10.py new file mode 100644 index 0000000000000000000000000000000000000000..94f531fe3588db4b6adb8d2c6f2fb4e59e0c5ce4 --- /dev/null +++ b/homework_01_python/homework_python10.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Nov 19 16:14:33 2022 + +@author: Zuo zijun +""" + +def existnumber(num, x): + for i in range(len(num)-1): + for j in range(i+1, len(num)): + sum = 0; + for k in range(i, j+1): + sum = sum + num[k] + if sum % x == 0 : + return True + else: + pass + +sz = input("请以x1,x2,...,xn形式输入数组:") +stra = sz.split(',') +a = [] +for x in stra: + a.append(int(x)) +print(a) +number = int(input("请输入数字:")) +if existnumber(a, number): + print("true") +else: + print("false") \ No newline at end of file diff --git a/homework_01_python/homework_python11.py b/homework_01_python/homework_python11.py new file mode 100644 index 0000000000000000000000000000000000000000..a1b1d187b8249c3a3c4bb873794a5f919f807496 --- /dev/null +++ b/homework_01_python/homework_python11.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Nov 19 16:33:48 2022 + +@author: Zuo zijun +""" + +def isunique(astr): + if len(astr)==len(set(astr)): + print ("True") + else: + print ("False") +str1=input("please input a string:") +isunique(str1) \ No newline at end of file diff --git a/homework_01_python/homework_python12.py b/homework_01_python/homework_python12.py new file mode 100644 index 0000000000000000000000000000000000000000..cd5b668604f7bab72423997a4774fda3e15d9c40 --- /dev/null +++ b/homework_01_python/homework_python12.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Nov 19 16:36:00 2022 + +@author: Zuo zijun +""" + +astr=input("please input a string:") +count_b=astr.count('b') +count_a=astr.count('a') +count_l=astr.count('l')//2 +count_o=astr.count('o')//2 +count_n=astr.count('n') +print(min(count_b,count_a,count_l,count_o,count_n)) \ No newline at end of file diff --git a/homework_01_python/homework_python13.py b/homework_01_python/homework_python13.py new file mode 100644 index 0000000000000000000000000000000000000000..e00b25e80ba9f90ae6ef120ed2132cf946f8d8e2 --- /dev/null +++ b/homework_01_python/homework_python13.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Nov 19 16:37:29 2022 + +@author: Zuo zijun +""" + +import random +list1=[] +for x in range(65,91): + a=str(chr(x)) + list1.append(a) +for x in range(97,123): + b=str(chr(x)) + list1.append(b) +for x in range(10): + list1.append(str(x)) +def gen_code(): + s='' + for x in range(11): + a=random.choice(list1) + s+=a + print(s) +for x in range(200): + gen_code() \ No newline at end of file diff --git a/homework_01_python/homework_python14.py b/homework_01_python/homework_python14.py new file mode 100644 index 0000000000000000000000000000000000000000..ff02eb5e889ad8bc804e3e6191b3066911927406 --- /dev/null +++ b/homework_01_python/homework_python14.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Nov 19 16:38:46 2022 + +@author: Zuo zijun +""" + +import os +def get_files(dir,suffix): + res=[] + for root,directory,files in os.walk(dir): + for filename in files: + name, suf = os.path.splitext(filename) + if suf == suffix: + res.append(os.path.join(root,filename)) + return res +for file in get_files("./",'.dll'): + print(file) \ No newline at end of file diff --git a/homework_01_python/homework_python15.py b/homework_01_python/homework_python15.py new file mode 100644 index 0000000000000000000000000000000000000000..3f608d9080b82571ad68597605d209cf99e4fba8 --- /dev/null +++ b/homework_01_python/homework_python15.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Nov 19 16:40:00 2022 + +@author: Zuo zijun +""" + +import os + + +def get_all_file(path): + file_list = [] + for file in os.listdir(path): + if os.path.splitext(file)[1]=='.py': + file_list.append(path +'/'+file) + print('添加',file) + return file_list + + +def get_rows(file): + with open(file,encoding='utf8') as f: + lines = f.readline() + rows = len(lines) + vv =0 + space =0 + for line in lines: + if line =='\n': + space +=1 + if line[0]=="#": + vv+=1 + date ={ + 'rows':rows, + 'vv':vv, + 'space':space + } + return date + + +def run(path): + file_list = get_all_file(path) + + all_rows =0 + all_vuui=0 + all_space= 0 + + for file in file_list: + date = get_rows(file) + print("正在计算",file) + rows = date.get( 'rows') + vv = date.get('vv') + space = date.get('space') + all_rows += rows + all_space +=space + all_vuui +=vv + print('所有代码的行数:{}\n其中包括的注释行数:{}\n其中空格行数:{}'.format(all_rows, all_vuui, all_space)) + + +if __name__ =='__main__': + path = 'C:\\Users\\Zuo zijun\\machinelearning_homework\\homework_01_python' + run(path=path) \ No newline at end of file diff --git a/homework_01_python/homework_python2.py b/homework_01_python/homework_python2.py new file mode 100644 index 0000000000000000000000000000000000000000..700bf98912a22925e5bc65d0c442d0f45a7bfaf7 --- /dev/null +++ b/homework_01_python/homework_python2.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Nov 14 20:04:12 2022 + +@author: Zuo zijun +""" + + +number=0; +for a in range(1,5): + for b in range(1,5): + for c in range(1,5): + if a!=b & a!=c & b!=c: + print(a*100+b*10+c); + number=number+1; +print('组成不相同且无重复数字的个数为',number) \ No newline at end of file diff --git a/homework_01_python/homework_python3.py b/homework_01_python/homework_python3.py new file mode 100644 index 0000000000000000000000000000000000000000..b23e998ed9fe8e4b68b5a4137369b77551504a96 --- /dev/null +++ b/homework_01_python/homework_python3.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Nov 14 20:19:32 2022 + +@author: Zuo zijun +""" + +jj=eval(input("请输入当月利润(万元):")) +lr=0; +if jj<=10: + lr=jj*0.1 +elif jj>10 and jj<=20: + lr=10*0.1+(jj-10)*0.075 +elif jj>20 and jj<=40: + lr=(jj-20)*0.05 +elif jj>40 and jj<=60: + lr=(jj-40)*0.03 +elif jj>60 and jj<=100: + lr=(jj-60)*0.015 +elif jj>100: + lr=(jj-100)*0.01 +print("当月应发奖金%.*f万元"%(3,lr)) \ No newline at end of file diff --git a/homework_01_python/homework_python4.py b/homework_01_python/homework_python4.py new file mode 100644 index 0000000000000000000000000000000000000000..967780e4ec429364429d5b782ce06711f7f4faaf --- /dev/null +++ b/homework_01_python/homework_python4.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Nov 14 20:58:25 2022 + +@author: Zuo zijun +""" +for i in range(10): + for j in range(10): + if i==9: + print()\ + else: cj=i*j; + print(f"{i}x{j}={cj}") \ No newline at end of file diff --git a/homework_01_python/homework_python5.py b/homework_01_python/homework_python5.py new file mode 100644 index 0000000000000000000000000000000000000000..c3bfe7dc1df578fc2ef48cf4c6cb9e421045f6fc --- /dev/null +++ b/homework_01_python/homework_python5.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Nov 19 09:02:45 2022 + +@author: Zuo zijun +""" + +a=2 +sum=0 +while a<=100: + if a%2==0: + sum=sum+a + elif a%2==1: + sum=sum-a + a+=1 +print("sum={}".format(sum)) \ No newline at end of file diff --git a/homework_01_python/homework_python6.py b/homework_01_python/homework_python6.py new file mode 100644 index 0000000000000000000000000000000000000000..402812438cffe80b5071cffcd71c5ab223c92175 --- /dev/null +++ b/homework_01_python/homework_python6.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Nov 19 10:12:22 2022 + +@author: Zuo zijun +""" + +old_list=[1,10,4,2,9,2,34,5,9,8,5,0] +new_list=[] +for i in range(11,1,-1): + smallest=old_list[0] + for j in range(1,i): + if smallest<=old_list[j]: + pass + else: + smallest=old_list[j] + old_list.remove(smallest) + new_list.append(smallest) +new_list.append(old_list[0]) +print(new_list) \ No newline at end of file diff --git a/homework_01_python/homework_python7.py b/homework_01_python/homework_python7.py new file mode 100644 index 0000000000000000000000000000000000000000..19cc503968bfebbbd96c1621e59d098670bdedb9 --- /dev/null +++ b/homework_01_python/homework_python7.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +""" +Created on Sat Nov 19 15:19:24 2022 + +@author: Zuo zijun +""" + +def searchMatrix(matrix,target): + target = eval(input("请输入目标值:")) + matrix = eval(input("请输入矩阵:")) + if not matrix: + return False + row=len(matrix) + col=len(matrix[0]) + i=row-1 + j=0 + judge=False + while(i>=0) or (j