Pulling it together


#1

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

says:

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

what is wrong?


#2

Seems like you answered your own question, all on the same line.
Perhaps you'd like to ask something more specific.
And if your code is relevant to your question, then make sure it's intact.


#3

I did not understand what you said


#4

Do you have a question?

You asked "what is wrong" but you answered that yourself.


#5

I am stuck in the last step of "Taking a vacation".Is there something wrong in my code?


#6

The error message is telling you what is wrong with your code. @ionatan is trying to tell you the same thing. You are first posting the exact problem with your code ("It looks like nothing was printed to the console!") and then asking:

Did you even read the error message?


Anyway, do you now know how to fix the problem?


#7

no,I do not how to fix it.and i actually do no understand the error message.


#8

The error you get is:

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

The error message is telling you that no text is being printed in the console. That means that your code is not executing the print command to print the expected text.

Your code does have the print statement, but it's inside trip_cost method. You'll want the print statement to be out of the trip_cost method. Do you know how to do this?


#9

no,Sir,I do not,I am beginner,and still trying to understand this language


#10

I will try my best to help you. Do you at least understand the error message after what I told before in this post?


#11

yes,sir.I understood it.


#12

Wonderful! Now, to help you fix the code.

Remember that the print statement print trip_cost("Los Angeles",5,600) has to be outside the trip_cost function. If the print statement is inside the function trip_cost, the print statement will only be executed when you call the trip_cost function.

Consider an analogy, there are plenty of things in your house (your code). Some things are accessed directly, like the television, because they are directly inside the house. Other things like the ice cream (your print statement), which is inside the fridge), will only be accessed when you open the fridge (the trip_cost function).

The exercise wants your ice cream (print statement) to be able to be accessed directly, hence it has to be outside the fridge (trip_cost function).

Now, back to code. To recap, currently your print statement is inside the function:

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

because it is indented four spaces to the right.

Do you now know how to fix the code?


#13

Sir,I tried to modify my code after you said to take out the print statement out of the trip_cost.And I wrote this code and it worked..

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

#14

This code is correct.Right?But it seems you are telling me about another way.Please tell me if it is.I would like to learn that too.


#15

Congratulations on passing the exercise! I wish you good luck for the rest of the exercises :smiley:


#16

Thank you sir, For your help.It was very much helpful.


#17

I was able to solve the problem. Thank you for your help.


#18

2 posts were split to a new topic: It keeps giving me back an Oops message


#19

Nice one, I had some issues with this exercise also, and by looking at your code, after trying to rewrite mine once more time I finally found the "bug" :smile:

Thx


#22