完成作业3-2-1
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import math
|
||||
|
||||
A = [3, 4]
|
||||
B = [1, 2]
|
||||
|
||||
# 1. A + B
|
||||
add_result = [a + b for a, b in zip(A, B)]
|
||||
print("A + B =", add_result)
|
||||
|
||||
# 2. 2 × A
|
||||
scalar_result = [2 * a for a in A]
|
||||
print("2 × A =", scalar_result)
|
||||
|
||||
# 3. A的长度
|
||||
norm = math.sqrt(sum(a**2 for a in A))
|
||||
print("A的长度 =", norm)
|
||||
Reference in New Issue
Block a user