From 07d3255376af25c2d6ddabd6cc2aff640472c37d Mon Sep 17 00:00:00 2001 From: Mingkun Wang Date: Mon, 27 Feb 2023 16:43:01 +0800 Subject: [PATCH 1/4] Create README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..96f8bed --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# 965PythonLearningArchive +Archive for my projects while learning python. Your suggestions are welcome From a6689d7352170ee36722476c143d326563cb5b3a Mon Sep 17 00:00:00 2001 From: Mingkun Wang Date: Mon, 13 Mar 2023 15:03:23 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Calculate.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Calculate.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Calculate.py b/Calculate.py index e6af384..4626036 100755 --- a/Calculate.py +++ b/Calculate.py @@ -7,7 +7,8 @@ eval()函数可对括号中的含变量表达式做运算 " 1 2 3 4 5 " -7 -6 -5 -4 -3 -2 -1 :反向递减序号 使用[]获取字符串中一个或多个字符 -str[0]获取第一个字 str[0:2]获取前两个字 str[0:-1]字符串去掉末位后输出 str[1:]去首位 +str[0]获取第一个字 str[0:2]获取前两个字 str[0:-1]字符串去掉末位后输出 str[1:]去首位 +str[m:n[:k]]m位至n位,k为步长 ['F', 'f', '℉'] : 列表类型数据 ''' numdata = eval(In[0:-1]) From 4dfd1e6b698b0bea2b7b6a37bcc183f38c84b5a0 Mon Sep 17 00:00:00 2001 From: Mingkun Wang Date: Mon, 13 Mar 2023 15:03:23 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20Calculate.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- .idea/pythonProject1.iml | 2 +- Calculate.py | 19 +++++++++++-- Turtle.py | 2 -- iSmartAnsAnalize/scripts.py | 53 +++++++++++++++++++++++++++++++++++++ temp.py | 0 6 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 iSmartAnsAnalize/scripts.py create mode 100644 temp.py diff --git a/.idea/misc.xml b/.idea/misc.xml index 11aefe8..62978b6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/.idea/pythonProject1.iml b/.idea/pythonProject1.iml index 78dd7ad..ff009a2 100644 --- a/.idea/pythonProject1.iml +++ b/.idea/pythonProject1.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/Calculate.py b/Calculate.py index 4626036..e975920 100755 --- a/Calculate.py +++ b/Calculate.py @@ -4,11 +4,12 @@ In = input() ''' eval()函数可对括号中的含变量表达式做运算 0 1 2 3 4 5 6 :正向递增序号 -" 1 2 3 4 5 " +a b c d e f g -7 -6 -5 -4 -3 -2 -1 :反向递减序号 使用[]获取字符串中一个或多个字符 -str[0]获取第一个字 str[0:2]获取前两个字 str[0:-1]字符串去掉末位后输出 str[1:]去首位 +str[0]获取第一个字 str[0:2]获取前两个字 str[0:-1]字符串去掉末位后输出 str[1:]去首位 str[m:n[:k]]m位至n位,k为步长 +str[::-1]倒置字符串 ['F', 'f', '℉'] : 列表类型数据 ''' numdata = eval(In[0:-1]) @@ -34,3 +35,17 @@ elif In[-1] in ['C', 'c', '°C']: else: print("Syntax Error") +''' +import math # 引入math库 + +a = float(input()) +b = float(input()) +c = float(input()) +delta = math.pow(b, 2) - 4 * a * c# 计算判别式 +if delta >= 0: + x1 = (-b + math.sqrt(delta)) / (2 * a) + x2 = (-b - math.sqrt(delta)) / (2 * a) #括号很重要!!!!!!!!! + print("X1=", round(x1, 2), " X2=", round(x2, 2)) +else: + print("没有实数解") +''' diff --git a/Turtle.py b/Turtle.py index e16f37a..721b561 100755 --- a/Turtle.py +++ b/Turtle.py @@ -83,7 +83,6 @@ for i in range(0, 5): pendown() circle(100) ''' -''' import turtle @@ -103,4 +102,3 @@ y = [-75, -75, -75, -155, -155] for i in range(5): circle(x[i], y[i], 360, 100, 15, color[i]) turtle.done() -''' diff --git a/iSmartAnsAnalize/scripts.py b/iSmartAnsAnalize/scripts.py new file mode 100644 index 0000000..31acc48 --- /dev/null +++ b/iSmartAnsAnalize/scripts.py @@ -0,0 +1,53 @@ +# encoding utf-8 +import linecache +import re +import os + + +def opentxt(num, path, name, line): + filename = '.\\{0}\\{1}{2}.txt'.format(path, num, name) + cont = linecache.getline(filename, line) + return cont + + +def savetxt(num, path, inv, name, character): + filename = '.\\{0}\\{1}{2}.txt'.format(path, num, name) + with open(filename, 'w', encoding='UTF-8') as txt: + txt.write(inv.replace(character, '\n')) + + +def txtsearch(num, path, character): + filename = '.\\{0}\\{1}_Response.txt'.format(path, num) + txt = open(filename, 'r', encoding='UTF-8') + lines = txt.readlines() + for lines in lines: # 对TXT 进行逐行读取 + if character in lines: + return lines + txt.close() + + +count = 2 +while count < 26: + content = txtsearch(count, 'response', 'answer') + texts = re.findall(r'.*<\\/answers>', content) + texts = str(texts) + texts = re.findall(r'CDATA\[.]', texts) + texts = str(texts) + texts = texts.replace("'CDATA[]]'", '\n') + texts = texts.replace("CDATA", '') + savetxt(count, 'Ans', texts, 'ans', ',') + count += 1 + +os.chdir(r"C:/Users/965/Builds/iSmartAnsCatch/Ans") +filedir = "C:/Users/965/Builds/iSmartAnsCatch/Ans" +f = open('../Ans.txt', 'w') +# 遍历文件名 +for i in range(2, 26): + filename1 = str(i) + 'ans.txt' + if i > 0: + filepath = filedir + '/' + filename1 + # 遍历单个文件 读取行数 + for line1 in open(filepath, encoding='UTF-8'): + f.writelines(str(i - 1) + line1) + f.write('\n') +f.close() diff --git a/temp.py b/temp.py new file mode 100644 index 0000000..e69de29 From 51dce155c298140a1d4a322c4a2fcfda2acd013d Mon Sep 17 00:00:00 2001 From: 965 Date: Wed, 10 May 2023 11:38:53 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Calculate.py | 38 +++++++++++ datatype_info.py | 52 +++++++++++++++ iris_sepal_length.csv | 150 ++++++++++++++++++++++++++++++++++++++++++ note.md | 90 ++++++++++++++++++++++++- temp.py | 17 +++++ 5 files changed, 346 insertions(+), 1 deletion(-) create mode 100644 iris_sepal_length.csv diff --git a/Calculate.py b/Calculate.py index e975920..d4652b4 100755 --- a/Calculate.py +++ b/Calculate.py @@ -49,3 +49,41 @@ if delta >= 0: else: print("没有实数解") ''' +''' +import sys +operation = ["+", "-", "*", "/"] +for i in range(3): + strin = input() + strin1 = strin.split(operation[i], 2)[0] + strin2 = strin.split(operation[i], 2)[-1] + outp = 0 + strin1 = float(strin1) + strin2 = float(strin2) + if operation[i] in strin: + if i == 0: + outp = strin1 + strin2 + elif i == 1: + outp = strin1 - strin2 + elif i == 2: + outp = strin1 * strin2 + elif i == 3: + outp = strin1 / strin2 + print(round(outp, 2)) +''' +''' +import math + +inp = input() +inp = float(inp.split(',', 2)[1]) / math.pow(float(inp.split(',', 2)[0]), 2) +limitg = (0, 18.5, 25, 30, 999999999999999) +limitcn = (0, 18.5, 24, 28, 999999999999999) +outp = ('偏瘦', '正常', '偏胖', '肥胖') +for i in range(0, 5): + if limitg[i] <= float(inp) < limitg[i + 1]: + outg = outp[i] + if limitcn[i] <= float(inp) < limitcn[i + 1]: + outcn = outp[i] + +print(\'''BMI数值为:{0} +BMI指标为:国际'{1}',国内'{2}\'\'''.format(round(inp, 2), outg, outcn)) +''' \ No newline at end of file diff --git a/datatype_info.py b/datatype_info.py index 1de0d0f..4f647c3 100755 --- a/datatype_info.py +++ b/datatype_info.py @@ -7,4 +7,56 @@ print(r'') ''' r = (85 - 72) / 72 * 100 print(f'{r:.1f}%') +''' +s = input("") # 输入一个字符串 +ls = [] +for c in s: + ls.append(str(ord(str(c)))) +print(','.join(ls)) +''' +''' +s = \'''双儿 洪七公 赵敏 赵敏 逍遥子 鳌拜 殷天正 金轮法王 乔峰 杨过 洪七公 郭靖 + 杨逍 鳌拜 殷天正 段誉 杨逍 慕容复 阿紫 慕容复 郭芙 乔峰 令狐冲 郭芙 + 金轮法王 小龙女 杨过 慕容复 梅超风 李莫愁 洪七公 张无忌 梅超风 杨逍 + 鳌拜 岳不群 黄药师 黄蓉 段誉 金轮法王 忽必烈 忽必烈 张三丰 乔峰 乔峰 + 阿紫 乔峰 金轮法王 袁冠南 张无忌 郭襄 黄蓉 李莫愁 赵敏 赵敏 郭芙 张三丰 + 乔峰 赵敏 梅超风 双儿 鳌拜 陈家洛 袁冠南 郭芙 郭芙 杨逍 赵敏 金轮法王 + 忽必烈 慕容复 张三丰 赵敏 杨逍 令狐冲 黄药师 袁冠南 杨逍 完颜洪烈 殷天正 + 李莫愁 阿紫 逍遥子 乔峰 逍遥子 完颜洪烈 郭芙 杨逍 张无忌 杨过 慕容复 + 逍遥子 虚竹 双儿 乔峰 郭芙 黄蓉 李莫愁 陈家洛 杨过 忽必烈 鳌拜 王语嫣 + 洪七公 韦小宝 阿朱 梅超风 段誉 岳灵珊 完颜洪烈 乔峰 段誉 杨过 杨过 慕容复 + 黄蓉 杨过 阿紫 杨逍 张三丰 张三丰 赵敏 张三丰 杨逍 黄蓉 金轮法王 郭襄 + 张三丰 令狐冲 赵敏 郭芙 韦小宝 黄药师 阿紫 韦小宝 金轮法王 杨逍 令狐冲 阿紫 + 洪七公 袁冠南 双儿 郭靖 鳌拜 谢逊 阿紫 郭襄 梅超风 张无忌 段誉 忽必烈 + 完颜洪烈 双儿 逍遥子 谢逊 完颜洪烈 殷天正 金轮法王 张三丰 双儿 郭襄 阿朱 + 郭襄 双儿 李莫愁 郭襄 忽必烈 金轮法王 张无忌 鳌拜 忽必烈 郭襄 令狐冲 + 谢逊 梅超风 殷天正 段誉 袁冠南 张三丰 王语嫣 阿紫 谢逊 杨过 郭靖 黄蓉 + 双儿 灭绝师太 段誉 张无忌 陈家洛 黄蓉 鳌拜 黄药师 逍遥子 忽必烈 赵敏 + 逍遥子 完颜洪烈 金轮法王 双儿 鳌拜 洪七公 郭芙 郭襄 赵敏''\' +d = {} +count = 0 +for i in s.split(): + if i in d: + d[i] += 1 + else: + d[i] = 1 +print(max(d, key=d.get))''' +''' +import numpy as np +L = [[2.73351472, 0.47539713, 3.63280356, 1.4787706, 3.13661701], + [1.40305914, 2.27134829, 2.73437132, 1.88939679, 0.0384238], + [1.56666697, -0.40088431, 0.54893762, 3.3776724, 2.27490386]] +arr = np.array(L) +arr1 = np.array((arr[0][1], arr[1][1], arr[2][1])) +arr1 = arr1.reshape(3, 1) +arr2 = np.array((arr[1][2:5], arr[2][2:5])) +arr3 = np.array((arr[0][1:5:2], arr[2][1:5:2])).flatten() +arr4 = arr[np.where(np.logical_and(arr >= 2.5, arr <= 3.5))] +arr5 = arr[np.where(np.logical_or(arr >= 3, arr <= 0))] +print(f\'''arr1= {arr1} +arr2= {arr2} +arr3= {arr3.flatten()} +arr4= {arr4} +arr5= {arr5}\''') +''' diff --git a/iris_sepal_length.csv b/iris_sepal_length.csv new file mode 100644 index 0000000..696a806 --- /dev/null +++ b/iris_sepal_length.csv @@ -0,0 +1,150 @@ +5.1 +4.9 +4.7 +4.6 +5.0 +5.4 +4.6 +5.0 +4.4 +4.9 +5.4 +4.8 +4.8 +4.3 +5.8 +5.7 +5.4 +5.1 +5.7 +5.1 +5.4 +5.1 +4.6 +5.1 +4.8 +5.0 +5.0 +5.2 +5.2 +4.7 +4.8 +5.4 +5.2 +5.5 +4.9 +5.0 +5.5 +4.9 +4.4 +5.1 +5.0 +4.5 +4.4 +5.0 +5.1 +4.8 +5.1 +4.6 +5.3 +5.0 +7.0 +6.4 +6.9 +5.5 +6.5 +5.7 +6.3 +4.9 +6.6 +5.2 +5.0 +5.9 +6.0 +6.1 +5.6 +6.7 +5.6 +5.8 +6.2 +5.6 +5.9 +6.1 +6.3 +6.1 +6.4 +6.6 +6.8 +6.7 +6.0 +5.7 +5.5 +5.5 +5.8 +6.0 +5.4 +6.0 +6.7 +6.3 +5.6 +5.5 +5.5 +6.1 +5.8 +5.0 +5.6 +5.7 +5.7 +6.2 +5.1 +5.7 +6.3 +5.8 +7.1 +6.3 +6.5 +7.6 +4.9 +7.3 +6.7 +7.2 +6.5 +6.4 +6.8 +5.7 +5.8 +6.4 +6.5 +7.7 +7.7 +6.0 +6.9 +5.6 +7.7 +6.3 +6.7 +7.2 +6.2 +6.1 +6.4 +7.2 +7.4 +7.9 +6.4 +6.3 +6.1 +7.7 +6.3 +6.4 +6.0 +6.9 +6.7 +6.9 +5.8 +6.8 +6.7 +6.7 +6.3 +6.5 +6.2 +5.9 diff --git a/note.md b/note.md index 2b90ed7..18e14a9 100755 --- a/note.md +++ b/note.md @@ -13,6 +13,7 @@ print("{:.2f}".format(value)) 转义字符\可以转义很多字符,比如\n表示换行,\t表示制表符,字符\本身也要转义,所以\\表示的字符就是\ 如果字符串里面有很多字符都需要转义,就需要加很多\,为了简化,Python还允许用r''表示''内部的字符串默认不转义 如果字符串内部有很多换行,用\n写在一行里不好阅读,为了简化,Python允许用''''''的格式表示多行内容 +def(a, *b)a表示第一变量,*b表示后面全部变量 常见的占位符有: 占位符 替换内容 @@ -73,4 +74,91 @@ turtle.goto(x,y)、setpos(x,y)、setposition(x,y):由当前坐标前往指定 5.3 方向控制函数 turtle.setheading(angle) 或者 turtle.seth(angle):以绝对角度改变方向 turtle.left(angle) 或者 turtle.lt(angle):以海龟角度向左改变方向 -turtle.right(angle) 或者 turtle.rt(angle):以海龟角度向右改变方向 \ No newline at end of file +turtle.right(angle) 或者 turtle.rt(angle):以海龟角度向右改变方向 + + +Python列表函数&方法 + +Python包含以下函数: +序号 函数 +1 cmp(list1, list2) +比较两个列表的元素 +2 len(list) +列表元素个数 +3 max(list) +返回列表元素最大值 +4 min(list) +返回列表元素最小值 +5 list(seq) +将元组转换为列表 + +Python包含以下方法: +序号 方法 +1 list.append(obj) +在列表末尾添加新的对象 +2 list.count(obj) +统计某个元素在列表中出现的次数 +3 list.extend(seq) +在列表末尾一次性追加另一个序列中的多个值(用新列表扩展原来的列表) +4 list.index(obj) +从列表中找出某个值第一个匹配项的索引位置 +5 list.insert(index, obj) +将对象插入列表 +6 list.pop([index=-1]) +移除列表中的一个元素(默认最后一个元素),并且返回该元素的值 +7 list.remove(obj) +移除列表中某个值的第一个匹配项 +8 list.reverse() +反向列表中元素 +9 list.sort(cmp=None, key=None, reverse=False) +对原列表进行排序 + +s = input("") # 输入一个字符串 +ls = [] +for c in s: + ls.append(str(ord(str(c)))) +print(','.join(ls)) +Python join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。 +set + +set和dict类似,也是一组key的集合,但不存储value。由于key不能重复,所以,在set中,没有重复的key。 + +要创建一个set,需要提供一个list作为输入集合: + +>>> s = set([1, 2, 3]) +>>> s +{1, 2, 3} + +注意,传入的参数[1, 2, 3]是一个list,而显示的{1, 2, 3}只是告诉你这个set内部有1,2,3这3个元素,显示的顺序也不表示set是有序的。。 + +重复元素在set中自动被过滤: + +>>> s = set([1, 1, 2, 2, 3, 3]) +>>> s +{1, 2, 3} + +通过add(key)方法可以添加元素到set中,可以重复添加,但不会有效果: + +>>> s.add(4) +>>> s +{1, 2, 3, 4} +>>> s.add(4) +>>> s +{1, 2, 3, 4} + +通过remove(key)方法可以删除元素: + +>>> s.remove(4) +>>> s +{1, 2, 3} + +set可以看成数学意义上的无序和无重复元素的集合,因此,两个set可以做数学意义上的交集、并集等操作: + +>>> s1 = set([1, 2, 3]) +>>> s2 = set([2, 3, 4]) +>>> s1 & s2 +{2, 3} +>>> s1 | s2 +{1, 2, 3, 4} + +set和dict的唯一区别仅在于没有存储对应的value,但是,set的原理和dict一样,所以,同样不可以放入可变对象,因为无法判断两个可变对象是否相等,也就无法保证set内部“不会有重复元素”。试试把list放入set,看看是否会报错。 \ No newline at end of file diff --git a/temp.py b/temp.py index e69de29..38e6f43 100644 --- a/temp.py +++ b/temp.py @@ -0,0 +1,17 @@ +import numpy as np + +L = [[2.73351472, 0.47539713, 3.63280356, 1.4787706, 3.13661701], + [1.40305914, 2.27134829, 2.73437132, 1.88939679, 0.0384238], + [1.56666697, -0.40088431, 0.54893762, 3.3776724, 2.27490386]] +arr = np.array(L) +arr1 = np.array((arr[0][1], arr[1][1], arr[2][1])) +arr1 = arr1.reshape(3, 1) +arr2 = np.array((arr[1][2:5], arr[2][2:5])) +arr3 = np.array((arr[0][1:5:2], arr[2][1:5:2])).flatten() +arr4 = arr[np.where(np.logical_and(arr >= 2.5, arr <= 3.5))] +arr5 = arr[np.where(np.logical_or(arr >= 3, arr <= 0))] +print(f'''arr1= {arr1} +arr2= {arr2} +arr3= {arr3.flatten()} +arr4= {arr4} +arr5= {arr5}''') \ No newline at end of file