print("NOTE: Parcels can only be smaller than 100x100x100cm (WxLxH) and weight less than 20kg")
parcelAmount = int(input("How many parcels are you sending?: "))
for i in range(parcelAmount):
parcelWidth.append(input("Please enter the width of the parcel " + str(i + 1) + ": "))
parcelLength.append(input("Please enter the length of the parcel " + str(i + 1) + ": "))
parcelHeight.append(input("Please enter the height of the parcel " + str(i + 1) + ": "))
parcelWeight.append(input("please enter the weight of the parcel " + str(i + 1) + ": "))
i = i + 1
if float(parcelWidth[i]) or float(parcelLength[i]) or float(parcelHeight[i]) > int(100) or float(parcelWeight[i]) > int(20):
parcelRej = parcelRej + 1
parcelAcc = parcelAmount - parcelRej
if float(parcelWeight[i]) > 1 and float(parcelWeight[i]) < 5:
parcelPrice[i] = 10
if float(parcelWeight[i]) > 5:
parcelPrice[i] = parcelWeight[i] - 5 + 10
print("There are " + str(parcelRej) + " parcels rejected")
print("There are " + str(parcelAcc) + " parcels accepted")
print("It will cost $" + str(sum(parcelPrice)) + " To ship the parcel")
此代碼找到要發送包裹的價格。我不斷收到所有if語句的「IndexError:列表索引超出範圍」,我不知道爲什麼請幫助我。提前致謝 :)。IndexError:列表索引超出範圍(在一個數組上)
這是一個完整的代碼,但堆棧溢出說,這是太多的代碼,並沒有足夠的細節,所以我只是補充本款增加空間,讓喜歡你們問我可以添加完整的代碼。那麼你們怎麼樣?你們從哪裏來?你們多大了?爲什麼它仍然太少的文字和太多的代碼...什麼時候這會結束?
通常這是(dums),因爲**索引超出範圍**。你確實知道'i'的值在'0'(包括)和'len(pracelLength)'(不包括)之間。 –
你可以顯示你的完整代碼以及迭代(for-loop,while循環)。 – shiva
至少可以提及parcelWidth,parcelLength,parcelHeight,parcelWeight的長度。 – shiva