Python:8.5.Taking A Vacation


#1

Good Afternoon Friends,I am stuck at https://www.codecademy.com/courses/python-beginner-P5YtY/1/4?curriculum_id=4f89dab3d788890003000096# .Following is my code:

def hotel_cost(nights):
    return 140* nights
    
##print hotel_cost(4)
 
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

##print plane_ride_cost("Tampa")


def rental_car_cost(days):
    car_rent = days*40
    if days>=7:
        return car_rent-50
    elif days>=3 and days<7:
        return car_rent-20
    return car_rent
    
##print rental_car_cost(5)


def tot_travel_cost(hotel_cost,plane_ride_cost,rental_car_cost):
    return hotel_cost + plane_ride_cost     + rental_car_cost
    
    
print tot_travel_cost(8,"Los Angeles",8)

I get following error message:

Traceback (most recent call last):
  File "python", line 34, in <module>
  File "python", line 31, in tot_travel_cost
TypeError: unsupported operand type(s) for +: 'int' and 'str'

What does it mean? Where am I making mistake?Please Help me.


#2

Hi @digitalace48666,

This ...

def tot_travel_cost(hotel_cost,plane_ride_cost,rental_car_cost):
    return hotel_cost + plane_ride_cost     + rental_car_cost

... should be a trip_cost function, and it needs to actually call the other functions, passing them city or days, as appropriate. The header should be ...

def trip_cost(city, days):

Then inside the function, call the other functions, as follows ...

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

Instead of this, you will need to call the trip_cost function, with proper arguments...

print tot_travel_cost(8,"Los Angeles",8)

#3

Thank You very much , I was doing so good today I got cocky and careless.


#5

This topic is solved.