import csv
NUM = 0
with open("E:\zuhe66.csv", 'r', newline='') as f:
reader = csv.reader(f)
for row in reader:
# print("row的值",row)
ab1 = []
ab2 = []
for i in row: #将i转换成float型
ab1.append(float(i))
print(ab1)
for x in (0, 1, 2, 3, 4, 5, 6, 7):
global NUM
NUM = NUM + 1 #全局变量赋值时,必须先声明,即在之前加上global NUM
for y in (0, 1, 2, 3, 4, 5, 6, 7):
z1 = ab1[1] * x + ab1[2] * y
# z2 = ab2[1] * x + ab2[2] * y
print("z1=",round(z1))
print(NUM)
定义好全局变量后,等到给全局变量赋值时,必须先声明,即在之前加上global NUM,才能再次使用。