1. 修改python程式,改成自己的加油記錄
from datetime import datetime
list=[
#修改此處
[ "2020-05-08", 30296.9, 0.0 ],
[ "2020-05-20", 30426.6, 4.74 ],
[ "2020-05-29", 30547.7, 4.56 ],
#可在此新增記錄
]
for i in range(len(list)):
if i==0:
continue
else:
print(list[i][0], end='\t') #注意:不是sep
num=datetime.strptime(list[i][0], "%Y-%m-%d")-datetime.strptime(list[i-1][0], "%Y-%m-%d")
print(num.days, "天", end='\t')
print((list[i][1]-list[i-1][1])/list[i][2], 'km/L', ) # unsupported operand type(s) for +: 'float' and 'str'
2. 把程式貼到這個網頁 https://ideone.com/
3.左下腳選Python 3,點Run
結果如下:
2020-05-20 12 天 27.36286919831162 km/L
2020-05-29 9 天 26.55701754386013 km/L