From cc5eb409f698d8d3bdfef4865eba9266df60dd76 Mon Sep 17 00:00:00 2001 From: 2509165035 <2509165035@student.edu.cn> Date: Tue, 21 Apr 2026 11:27:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Yy.py | 42 +++++++++++++++++++++++++ task-3-2-1-Text-Processing-Introduction | 1 + 2 files changed, 43 insertions(+) create mode 100644 Yy.py create mode 160000 task-3-2-1-Text-Processing-Introduction diff --git a/Yy.py b/Yy.py new file mode 100644 index 0000000..a6200ba --- /dev/null +++ b/Yy.py @@ -0,0 +1,42 @@ +s = "Hello" +for char in s: + print(f"'{char}' 的ASCII码: {ord(char)}") + print(f"ASCII码65对应的字符: {chr(65)}") +import math + +# 题目3 +A = [3, 4] +B = [1, 2] +# 1. A+B +A_plus_B = [A[0]+B[0], A[1]+B[1]] +# 2. 2*A +two_A = [2*A[0], 2*A[1]] +# 3. A的模 +norm_A = math.sqrt(A[0]**2 + A[1]**2) +print("题目3结果:") +print(f"A+B = {A_plus_B}") +print(f"2*A = {two_A}") +print(f"A的模 = {norm_A}") + +# 题目4 +A = [1, 2, 3] +B = [4, 5, 6] +# 1. 点积 +dot_product = sum(a*b for a,b in zip(A,B)) +# 2. 余弦相似度 +norm_A = math.sqrt(sum(a**2 for a in A)) +norm_B = math.sqrt(sum(b**2 for b in B)) +cos_sim = dot_product / (norm_A * norm_B) +print("\n题目4-1、2结果:") +print(f"点积 = {dot_product}") +print(f"余弦相似度 = {cos_sim:.4f}") + +# 题目4-3 +A2 = [1, 0] +B2 = [0, 1] +dot_product2 = sum(a*b for a,b in zip(A2,B2)) +norm_A2 = math.sqrt(sum(a**2 for a in A2)) +norm_B2 = math.sqrt(sum(b**2 for b in B2)) +cos_sim2 = dot_product2 / (norm_A2 * norm_B2) +print("\n题目4-3结果:") +print(f"余弦相似度 = {cos_sim2}") \ No newline at end of file diff --git a/task-3-2-1-Text-Processing-Introduction b/task-3-2-1-Text-Processing-Introduction new file mode 160000 index 0000000..f1763eb --- /dev/null +++ b/task-3-2-1-Text-Processing-Introduction @@ -0,0 +1 @@ +Subproject commit f1763ebff3a384a6479375b601476ffcc80a2972