# Code Problem

#1

I can't get my trip to sum up properly. The error says for (Tampa, 6) the 'int' is not iterable. Help!

``````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
else:
return 475
def rental_car_cost(days):
if days >= 7:
return (40 * days) - 50
elif days >= 3:
return (40 * days) - 20
elif days < 3:
return (40 * days)
else:
return 0
def trip_cost(city, days):
sum(hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days))
return trip_cost``````

#2

You're doing something similar to: `sum(3)`, sum will try to iterate through its argument, computing the sum of its elements. 3 can't be iterated through.

#3

so is sum the wrong element? should it be 'add'?

#4

Why would you compute the sum of a single value? Consider what effect the `+` operator has and what value you are giving as an argument to the sum function

#5

Got it! I did a simple return with addition of the elements and it ran. Thanks!

#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.