I'm trying to create a code that will take in an input (example below)
Input:
BHK158 VEHICLE 11
OIUGHH MOTORCYCLE 34.46
BHK158 VEHICLE 12.000
TRIR TRUCK 2.0
BLAS215 MOTORCYCLE 0.001
END
and produce an output where each license plate number is listed and the total cost is listed beside (example below)
Corresponding output:
OIUGHH: 5.8582
BHK158: 5.75
TRIR: 2.666
BLAS215: 0.00017
The vehicle license plates are charged $0.25 per kilometer (the kilometers are the number values in the input list), trucks are charged $1.333 per kilometer, and motorcycles $0.17 per kilometer. The output is listed in descending order.
Here is my code thus far:
fileinput = input('Input: \n')
split_by_space = fileinput.split(' ')
vehicles = {}
if split_by_space[1] == 'VEHICLE':
split_by_space[2] = (float(split_by_space[2]) * 0.25)
elif split_by_space[1] == 'TRUCK':
split_by_space[2] = float(split_by_space[2]) * 1.333
elif split_by_space[1] == 'MOTORCYCLE':
split_by_space[2] = float(split_by_space[2]) * 0.17
if split_by_space[0] in vehicles:
previousAmount = vehicles[split_by_space[0]]
vehicles[split_by_space[0]] = previousAmount + split_by_space[2]
else:
vehicles[split_by_space[0]] = split_by_space[2]
Thanks, any help/hints would be greatly appreciated.