What's the problem with my code


#1


https://www.codecademy.com/courses/python-beginner-P5YtY/1/4?curriculum_id=4f89dab3d788890003000096

Oops, try again. trip_cost('Tampa', 9) raised an error: 'int' object is not iterable


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):
    if days >= 7:
        return (40 * days) - 50
    elif days >= 3 and days < 7:
        return (40 * days) -20
    else:
        return 40 * days

def trip_cost(city, days):
    return sum(
        rental_car_cost(days) +
        hotel_cost(days) +
        plane_ride_cost(city)
        )


#2

@arcblaster29881,
From
https://docs.python.org/2/library/functions.html
you can read
https://docs.python.org/2/library/functions.html#sum
in which it is stated
that you can use the sum() function
like
sum([1,2,3])

and in our case we could use
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)


#3

you need a space between the - and the 20


#4

hi,in my opinion, the problem is sum and "+",don't use then together.you can use "," instead of "+",or just use "+" without the function "sum".try again.


#5

and you missed a variable spending_money .may be you can code like this:return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money


#6

No, you dont need a space there.


#7

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