Hi. I have no problems with my code, but I am wondering why this happens.
When I set this code in (which is correct), everything is fine.
def hotel_cost(nights): return 140*nights def plane_ride_cost(city): if city=="Charlotte": return 183 elif city=="Tampa": return 220 elif city=="Pittsburgh": return 222 elif city=="Los Angeles": return 475 def rental_car_cost(days): cost=40*days if days >= 7: cost -=50 elif days >=3: cost -=20 else: return cost def rental_car_cost(days): cost=days*40 if days >= 7: cost -=50 return cost elif days >=3: cost -=20 return cost else: return cost def trip_cost(city,days,spending_money): sum=rental_car_cost(days)+hotel_cost(days)+plane_ride_cost(city)+spending_money return sum
When I add this code here:
def trip_cost(city,days,spending_money): sum=rental_car_cost(days)+hotel_cost(days)+plane_ride_cost(city) return sum
It doesn't work.
The error is:
trip_cost('Pittsburgh', 1, 58) returned 402 instead of the correct value 460
The only difference between code 1 and code 2 is I got rid of "+spending_money" at the end.
Why does the first one work and not the second. I didn't even mention "spending_money" anywhere before in the code. How does the system know to add money when there isn't even a number or a variable connected with "spending_money"?
This has been puzzling me for a while.