From 5fa066766f0c0cb05c219664d5784e09308e8586 Mon Sep 17 00:00:00 2001 From: 2509165020 <2509165020@student.edu.cn> Date: Tue, 21 Apr 2026 11:24:43 +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 --- 260421+2509165020/test1.py | 7 +++++++ 260421+2509165020/test2.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 260421+2509165020/test1.py create mode 100644 260421+2509165020/test2.py diff --git a/260421+2509165020/test1.py b/260421+2509165020/test1.py new file mode 100644 index 0000000..5486a24 --- /dev/null +++ b/260421+2509165020/test1.py @@ -0,0 +1,7 @@ +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/260421+2509165020/test2.py b/260421+2509165020/test2.py new file mode 100644 index 0000000..e338c17 --- /dev/null +++ b/260421+2509165020/test2.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