The Transport Authority is implementing a new Road Pricing system. The authorities decided that the cars will be charged based on distance travelled, on a per mile basis. A car will be charged $0.50/mi, a van $2.1/mi and taxis travel for free. Create a function to determine how much a particular vehicle would be charged based on a particular distance. The function should take as input the type of the car and the distance travelled, and return the charged price.
x = float(input("How many miles is driven?"))
y = (input("What car was driven?"))
The requirement is(emphasis mine):
...... The function should take as input the type of the car and the distance travelled, and return the charged price.
Another problem in your code is that expressions in your statements isn't checking the value of
car_type. Also, you should use more meaningful variable names(for example,
car_type instead of
def road_pricing(car_type, distance): if car_type == "car": return .50 * distance if car_type == "van": return 2.1 * distance if car_type == "taxi": return 0 car_type = raw_input("What car was driven? ") distance = float(input("How many miles is driven? ")) print road_pricing(car_type, distance)