Plan Your Trip!


I am stuck with this exercise. Can someone help?

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

The computer says:

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

Any ideas?


It says nothing was printed.
Was it?
Why would it have been?


I guess "if nothing was printed that means my print statement was not executed" :smiley:
Does this mean that my original indentation of the print statement made all functions above trip_cost "unavailable" for reference?


I'm not sure why the indentation of a single statement would change the availability of a couple of functions?

When that file is executed, python starts at the top, creates hotel_costs, then plane_ride_cost, then rental_car_cost, then trip_cost, and after that it reaches end of file and exits.


Was the paper four indentations away form the console? lol
I don't understand why removing the indentation before print trip_cost allowed printing.
Why did it make a difference?


If you have a file like so:

print 'hi'

Then it prints hi.

If you have a file like this:

def f():
    print 'hi'

Then that prints nothing, all it does is to create a function, and then it exits as there are no more statements to execute in the file.


Your print command is inside the trip_cost function, which means the print command is not being executed because the trip_cost function is not being called inside the script. So all you need to do is take the print command outside of the trip_cost function and the print command will be executed.


it trouble from your indentation broo
try like this

f trip_cost(city,days,spending_money):
return rental_car_cost(days) + plane_ride_cost(city) + hotel_cost(days) + spending_money
print trip_cost("Los Angeles", 5, 600)


Super Answer master !! Good one Thank you


It makes sense and it worked, thank you!


Ah, it makes sense, thanks!


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