Plan Your Trip! not printing the correct amount


#1



I'm not getting an error but the result doesn't seem correct, please see below

function hotel_cost at 0x7fd2b5af6938>
None


def hotel_cost(nights):
    print hotel_cost
    return nights * 140
hotel_cost(2)

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


#2

here:

def hotel_cost(nights):
    print hotel_cost

why would you print the function object?

Anyway, that causes the output you see.

You place the trip_cost function call:

print trip_cost('Los Angelos', 5, 600)

outside/after the trip_cost function declaration.


#3

why would you print the function object?

I usually print out the functions to make sure I'm doing the lessons correctly. Later I will erase them after verifying they work. I want to run the code with an output to make sure the syntax and logic is correct.

You place the trip_cost function call:

print trip_cost('Los Angelos', 5, 600)

outside/after the trip_cost function declaration.

So if I understand this correctly my code should now look like...?

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

#4

yes, it looks correct now. It works?


#5

I'm still receiving an error, see below.

Traceback (most recent call last):
File "python", line 25, in
File "python", line 23, in trip_cost
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'

Please share your thoughts
below is my code

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

#7

This has no match in the plane_ride_cost function.


#8

:sweat_smile: wow I can't believe I missed that error, thanks


#9

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