7. Plan Your Trip! (Print error)


Why is it not working?



Oops, try again. It looks like nothing was printed to the console!

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


make sure the function call is outside the function (hint: indention)


What does that mean?


well, a function only executes when you call it, you learned this in 7. functions

but the function call should be outside the function:

def example():
   print "lets call the function"

see how the function call has no indent? this will place it outside the function, causing the function to execute


Can you make a example from my code?
I dont understand it:(


maybe you should then revisit some exercises about functions?

in this exercise, you add the function call. see the hint, it mentions calling (which obviously refers to function calling)


like that?

def hotel_cost(nights):
return 140 * nights


what do you do in this exercise? add this code:

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

now, this is obviously the function call, since it is the function call syntax (which was covered in the previous section)

the function call should be outside the function, what is inside/outside a function is determined by indent in python


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