7. Plan Your Trip! (Print error)


#1



Why is it not working?

https://www.codecademy.com/courses/python-beginner-P5YtY/1/6?curriculum_id=4f89dab3d788890003000096


ERROR:

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)


#2

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


#3

What does that mean?


#4

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"
example()

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


#5

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


#6

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)


#7

like that?

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


#8

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


#9

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