From bdda7b32301e9197d1d896f022fd5d238cb2ee0f Mon Sep 17 00:00:00 2001 From: 2509165015 <2509165015@student.edu.cn> Date: Tue, 21 Apr 2026 11:20:54 +0800 Subject: [PATCH] =?UTF-8?q?3-2-1=20=E6=96=87=E6=9C=AC=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=AF=BC=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 0421+2509165015/1.py | 6 ++++++ 0421+2509165015/2.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 0421+2509165015/1.py create mode 100644 0421+2509165015/2.py diff --git a/0421+2509165015/1.py b/0421+2509165015/1.py new file mode 100644 index 0000000..111de1c --- /dev/null +++ b/0421+2509165015/1.py @@ -0,0 +1,6 @@ +print("=== 1. 打印Hello每个字符的ASCII码 ===") +for char in "Hello": + print(f"字符 '{char}' 的ASCII码: {ord(char)}") +print("\n=== 2. 验证 chr(65) ===") +result = chr(65) +print(f"chr(65) 的结果是: {result}") \ No newline at end of file diff --git a/0421+2509165015/2.py b/0421+2509165015/2.py new file mode 100644 index 0000000..e338c17 --- /dev/null +++ b/0421+2509165015/2.py @@ -0,0 +1,28 @@ +import math +print("===== 题目3 向量运算 =====") +A = [3, 4] +B = [1, 2] +A_plus_B = [a + b for a, b in zip(A, B)] +print(f"A + B = {A_plus_B}") +two_A = [2 * a for a in A] +print(f"2 * A = {two_A}") +norm_A = math.sqrt(sum(x**2 for x in A)) +print(f"A的模长 = {norm_A}") +print("\n===== 题目4 点积 & 余弦相似度 =====") +A1 = [1, 2, 3] +B1 = [4, 5, 6] +dot1 = sum(a*b for a, b in zip(A1, B1)) +norm_A1 = math.sqrt(sum(x**2 for x in A1)) +norm_B1 = math.sqrt(sum(x**2 for x in B1)) +cos1 = dot1 / (norm_A1 * norm_B1) +print(f"A1·B1 点积 = {dot1}") +print(f"A1、B1 余弦相似度 = {cos1:.4f}") +A2 = [1, 0] +B2 = [0, 1] +dot2 = sum(a*b for a, b in zip(A2, B2)) +norm_A2 = math.sqrt(sum(x**2 for x in A2)) +norm_B2 = math.sqrt(sum(x**2 for x in B2)) +cos2 = dot2 / (norm_A2 * norm_B2) +print(f"\nA2·B2 点积 = {dot2}") +print(f"A2、B2 余弦相似度 = {cos2}") +print("原因:两向量正交(夹角90°),余弦值为0") \ No newline at end of file