Files
task-3-2-1-Text-Processing-…/4.21.py
2509165029 f10cebebdf 4.21
2026-04-21 11:35:12 +08:00

35 lines
600 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)}")