Plan Your Trip!


#1


Hello,
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
    else:
        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)


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

The computer says:

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

Any ideas?
Cheers!



#2

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


#3

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?


#4

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.


#5

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?


#6

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.


#8

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.


#9

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)


#10

Super Answer master !! Good one Thank you


#11

It makes sense and it worked, thank you!


#12

Ah, it makes sense, thanks!


#13

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