Hey, You Never Know!


#1


  1. Hey, You Never Know!

Oops, try again. trip_cost('Pittsburgh', 3, 0) raised an error: 'int' object is not callable

It should work. I rechecked the indentation.


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
    else:
        return 0
def rental_car_cost(days):
    everyday = 40 * days
    if days >= 7:
        return everyday - 50
    elif 7 > days >= 3:
        return everyday - 20
    else:
        return everyday
def trip_cost(city, days, spending_money):
        spending_money
        trip_cost = rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) +                                                                   spending_money
    
        return trip_cost("Tampa", 10, 500)


#2

the function call:

trip_cost("Tampa", 10, 500)

should be outside/after the function. Just return the total cost of trip_cost in the function


#3

def trip_cost(city, days, spending_money):
trip_cost = rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money
return trip_cost("Tampa", 10, 500)

Unfortunately, it gives another indentation error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

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

def trip_cost(city, days, spending_money):
trip_cost = rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) +
spending_money
return trip_cost("Tampa", 10, 500)

File "python", line 26
return trip_cost
^
IndentationError: unindent does not match any outer indentation level


#4

i told you the function call should be outside the function, and i told you the return should return something different then it currently does


#5

File "python", line 26
SyntaxError: 'return' outside function


#6

yes, your trip_cost should return the total cost of your trip

then outside the function, call the function. Don't return the function call


#7

Thank you, Sir! That is how it goes:
def trip_cost(city, days, spending_money):
trip_cost = rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money
return trip_cost
trip_cost('Pittsburgh', 9, 0)


#8

yes, does that make sense?


#9

Well, at least I passed that exercise. Logically, it makes sense. Thank you.


#10

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