Reputation: 149
After compilation error:
Traceback (most recent call last):
File "python", line 29, in <module>
File "python", line 26, in trip_cost
TypeError: 'int' object is not callable
The following is the code for the expenditure calculation application that I wrote. There are four arguments passing inside trip_cost function in the end but four parameters defined in the function definition.
def hotel_cost(nights):
return 140 * nights
def spending_money(money):
return money
def plane_ride_cost(city):
if city == "Charlotte":
return 183
elif city == "Tampa":
return 220
elif city == "Pittsburgh":
return 222
elif city == "LosAngeles":
return 475
def rental_car_cost(days):
cost = 40
if days >= 7:
return (cost * days - 50)
elif days >= 3 < 7:
return (cost * days - 20)
elif days < 3:
return (cost * days)
def trip_cost(city,days,spending_money):
total_trip_cost = plane_ride_cost(city) + rental_car_cost(days) + hotel_cost(days) + spending_money(spending_money)
return total_trip_cost
print trip_cost("LosAngeles",5,600)
Upvotes: 0
Views: 60
Reputation: 1
def trip_cost(city,days,spending_money):
total_trip_cost = plane_ride_cost(city) + rental_car_cost(days) + hotel_cost(days) + spending_money(spending_money)
return total_trip_cost
on this part of the code, you are calling for the function spending_money(spending_money), the problem is that the variable and the function are named alike, so python asumes that you are calling the function inside the function??? why do humans do this to me, i feel confused, said python.
a good tip and solution is to change the variable name or function name.
try:
def trip_cost(city,days,travelling_cash):
total_trip_cost = plane_ride_cost(city) + rental_car_cost(days) +hotel_cost(days) + spending_money(travelling_cash)
return total_trip_cost
cheers mate!
Upvotes: 0
Reputation: 5377
Your local variable spending_money
is over-writing the function spending_money()
in your trip_cost
function's scope.
Since the spending_money()
function doesn't do anything, you could just add it directly.
Upvotes: 2