From f10cebebdfb5318d38f28015424b0785c994fb6b Mon Sep 17 00:00:00 2001 From: 2509165029 <2509165029@student.edu.cn> Date: Tue, 21 Apr 2026 11:35:12 +0800 Subject: [PATCH] 4.21 --- .idea/.gitignore | 3 ++ .idea/.name | 1 + .../inspectionProfiles/profiles_settings.xml | 6 ++++ .idea/misc.xml | 4 +++ .idea/modules.xml | 8 +++++ ...ask-3-2-1-Text-Processing-Introduction.iml | 8 +++++ .idea/vcs.xml | 6 ++++ 4.21.py | 35 +++++++++++++++++++ 8 files changed, 71 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/task-3-2-1-Text-Processing-Introduction.iml create mode 100644 .idea/vcs.xml create mode 100644 4.21.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..8701cdf --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +4.21.py \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d1e22ec --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..211bc2e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/task-3-2-1-Text-Processing-Introduction.iml b/.idea/task-3-2-1-Text-Processing-Introduction.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/task-3-2-1-Text-Processing-Introduction.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/4.21.py b/4.21.py new file mode 100644 index 0000000..bb42881 --- /dev/null +++ b/4.21.py @@ -0,0 +1,35 @@ +s = "Hello" +print("1. 字符 ASCII 码:") +for ch in s: + print(f" '{ch}' -> {ord(ch)}") + + +print("\n2. 验证 chr(65):") +print(f" chr(65) = '{chr(65)}'") + + +A = [3, 4] +B = [1, 2] + + + +def add_vectors(v1, v2): + return [v1[0] + v2[0], v1[1] + v2[1]] + + + +def scalar_multiply(scalar, v): + return [scalar * v[0], scalar * v[1]] + + + +import math +def vector_length(v): + return math.sqrt(v[0]**2 + v[1]**2) + +print("\n3. 向量计算:") +print(f" A = {A}") +print(f" B = {B}") +print(f" A + B = {add_vectors(A, B)}") +print(f" 2 × A = {scalar_multiply(2, A)}") +print(f" A 的模 = {vector_length(A)}") \ No newline at end of file