Whats wrong with my code? Please Help -_-


It says :
Traceback (most recent call last):
File "python", line 23, in
File "python", line 22, in trip_cost
TypeError: cannot concatenate 'str' and 'int' objects

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
        return "None"
def rental_car_cost (days):
    cost = days*40
    if days >=7:
        cost = cost - 50
    elif days >= 3:
        cost = cost - 20
    return cost
def trip_cost (city, days, spending_money):
    return plane_ride_cost (city) + hotel_cost (days) + rental_car_cost(days)            + spending_money
print trip_cost ("los Angeles", 5, 600)


the problem is here:

        return "None"

by returning None for a invalid city, you all of a sudden have to join integers and strings together, and that doesn't work.

the problem is also partly here:

print trip_cost ("los Angeles", 5, 600)

given los Angeles is not a valid destination, a string is returned instead of a integer, causing problems

try a valid destination, like Los Angeles


Should I use "false" instead of "None" ?


you can do that, but the point is just that this code is not designed to deal with a invalid destination.

that would mean that here:

return plane_ride_cost (city) + hotel_cost (days) + rental_car_cost(days) +spending_money

you try to join a boolean value and integers together. That wouldn't work either, i just recommend to call trip_cost with a valid destination, Los Angeles where Los is also spelled with uppercase first letter. This way, a integer gets returned, everything should work fine (string comparison is case sensitive)


Right. I got it. It works now.Thanks a lot ^^