我有三個清單list1是「汽車模型」list2是「每加侖價格(mpg)」,list3是「一年的總價」。我能夠遍歷3列,但我不知道如何依次獲得3列。請有人幫助我。先謝謝你!!如何遍歷3個列表並獲取Python中的3列?
繼承人我的代碼:
modelName = ['Toyota', 'Nissan', 'Honda']
fuelEfficiency = [15.0, 20.0, 30.0]
for i in range(len(modelName)):
print (modelName[i])
for i in range(len(fuelEfficiency)):
print (fuelEfficiency[i])
priceGas = 2.41
totalCost1 = (10000 * priceGas)/15.0
totalCost2 = (10000 * priceGas)/20.0
totalCost3 = (10000 * priceGas)/30.0
print (totalCost1)
print (totalCost2)
print (totalCost3)
我想輸出是這樣的:
MODEL COST(MPG) TOTALCOST
Toyota 15.0 1606.66
Nissan 20.0 1205.0
Honda 30.0 803.33
但是,這並不在Python 3.4 – HenryDev
@Henry工作,將我更新的代碼 – Hackaholic
我得到這個錯誤信息,你更新之後: – HenryDev