0
I am doubtful in a college exercise, I need to store 3 data which are: Vehicle number, mileage and consumption in each variable of type list, but due to be different types, with the first 2 being integer and the last float, apart from having the input on the same line, I can’t store them.
I thought I’d try to store it this way:
idcar=[] #Numero de cada veiculo
kms=[] #Quilometros rodados
consumo=[] #Consumo de cada veiculo
for i in range(10):
idcar[i],kms[i],consumo[i]=map(float,raw_input().split())
And then transform the float values (idcar and kms), to integer but for my misfortune appears this error:
Traceback (most recent call last):
File "consumo1.py", line 17, in <module>
idcar[i],kms[i],consume[i]=map(float,raw_input().split())
IndexError: list assignment index out of range
Since the entries are given this way, with 10 different values:
1001 231 59.2
1002 496 60.4
...
Adding important information that I forgot to put: At the end I should calculate the average consumption (Km/L) for each identified car and finally at the exit I should print for each car its average consumption, besides telling which are the 2 worst consumptions between cars.
I would like very much that they could help me, already grateful, I hope that I have written in a clear way my doubts, it is the first time that I write here.
I read what you suggested, it really seems like a great way to accomplish but maybe it’s because of my inexperience, I couldn’t insert the entry in the tuple and store it due to the values being inserted in the same line, subsequently the problem also asks to use the values of consumption and km to generate the average consumption (km/L) of each identified car and in the end I must print 2 lower values of the average consumption identify the number of the vehicle in which they are attached, as well as printing on each line the identification number of each car and its average consumption.
– Vinícius
@Vinicius added a few more comments in the reply; I believe that with this you can finish it alone.
– Woss
Solved the problem, was very fast after reading the functions that were very important for the exercise.
– Vinícius