5/7 Putting it all together


#1



This is the problem that I am stuck on:
https://www.codecademy.com/courses/python-beginner-P5YtY/1/4?curriculum_id=4f89dab3d788890003000096#

My error message:
Oops, try again. trip_cost('Charlotte', 9) raised an error: unsupported operand type(s) for -: 'str' and 'int'


My code:

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

def hotel_cost(days):
    return 140*days
    
def trip_cost(days,city):
    sum = rental_car_cost(days) + hotel_cost(days) +  plane_ride_cost(city)
    print sum
    return sum


#2

It asked you to return the sum not print it
So simply return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) and it will work .


#3

New error:

Oops, try again. trip_cost('Pittsburgh', 2) raised an error: unsupported operand type(s) for -: 'str' and 'int'

Can you please help with this?

Thank you.

P.S. The code is the same, except for the print statement on the second-to-last line.


#4

it's just simple like this : return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)


#5

You don't need to define a variable called sum.

It should look like this.

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

You're returning the sum of all of them. Which happens here. You don't need to define a new variable for it.


#6

hi there anyone who has been getting an error related to the trip cost use this code. i found this code on a blog and though there is no major difference this code gives guaranteed output.

def hotel_cost(days):
return days*140

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

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