I'm trying to find a way to solve a problem, but not sure how to do it, here it is:
I need to make a function that will receive the taxi fare of two companies and the fare will be a constant value and a value based on the kilometers traveled by the user, something like this:
company X: final_value_X = fixed_X (km_traveled*fare_per_km_X)
company Y: final_value_Y = fixed_Y (km_traveled*fare_per_km_Y)
After calculating that, I need to return in a string for the user which company will be cheaper to travel with in a format like this:
“Whatever” - if the value of the two companies for any race is equal
“company X” - if the value of company X is always lower than of company Y
“company Y” - if the value of company Y is always lower than of company X
“Company X when the distance < N, Whatever when the distance = N, Company Y when the distance > N” if the choice depends on the distance to be covered.
My problem is: How do I calculate the possibility number 4 if I am not being provided with the kilometers traveled by the user? How can I make a for-loop or while loop with that last possibility if I don't know which will be the time that the km_traveled will be cheaper than the fixed rate?
Right know, I'm doing a comparison with both values of the companies, but I don't know how to proceed for the rest of the problem and would really like some help, here is the code so far:
def company_fare_compare(fixed_X,fare_per_km_X,fixed_Y,fare_per_km_Y):
km = 0.0
cal_valor_taxi1 = float(tf1) (km*float(vqr1))
cal_valor_taxi2 = float(tf2) (km*float(vqr2))
while km <= 10:
cal_valor_taxi1
cal_valor_taxi2
if cal_valor_taxi1 < cal_valor_taxi2:
print("Empresa 1")
if cal_valor_taxi1 == cal_valor_taxi2:
print("Whatever")
if cal_valor_taxi1 > cal_valor_taxi2:
print("Empresa 2")
km = 1
CodePudding user response:
The kilometers traveled is not necessary information to solve this problem.
Also, adding kilometers to the count is not feasible either, since taxi clocks don't jump up suddenly by the per-km fare once a new km is begun - rather, they increase incrementally, in small, pro-rated jumps (i.e. = 1 is not feasible).
So, rather than doing what you've done, let's take a step back and try to think about the different cases with the input provided.
This looks like homework, so I will leave details out for the less straight-forward parts.
I can see the following:
Base fares are equal
- Per KM fees are equal -> X & Y cost the same, no matter the trip length
- Per KM fee of Y is cheaper -> Y is always cheaper
- Per KM fee of X is cheaper -> X is always cheaper
Base fare of Y is cheaper
- Per KM fees are equal -> Y is always cheaper
- Per KM fee of Y is cheaper -> Y is always cheaper
- Per KM fee of X is cheaper -> Find the "break-even" point at which X and Y cost the same, and over which X becomes cheaper than Y
Base fare of X is cheaper
- Per KM fees are equal -> X is always cheaper
- Per KM fee of X is cheaper -> X is always cheaper
- Per KM fee of Y is cheaper -> Find the "break-even" point at which X and Y cost the same, and over which Y becomes cheaper than X