我试图编写可以计算多块土地面积的代码。但是,我不明白数组和索引应该如何工作。
这是代码,但不起作用:
array = int(input('How many lands to process?'))
code = [0]*array
length = [0]*array
width = [0]*array
area = [0]*array2
for index in range(0,array):
code[index] = str(input('Enter a parcel code for each land.'))
for index in range(0,array):
length[index] = float(input('Enter the length in feet for each land.'))
for index in range(0,array):
width[index] = float(input('Enter the width in feet for each land.'))
area=0
for index in range(0,array2):
area[index]=float(length[index]*width[index])
for index in range(0,array2):
print(area[index])
for index in range(0,array):
print(code[index])