Help me please: the code is right but the console doesn't print!


#1


I have been stuck in this exercise for hours and no matter what I change, I keep getting the same error. I know the code is right because I looked in the Forums for help and it is exactly the way it should be. Please help me, I'm starting to think that this is a bug in console.

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

This is the error message: "Ops, tente outra vez. It looks like nothing was printed to the console!"
Due to the fact that the code is most likely right, It is supposed to PRINT THE ANSWER but it is just not happening.

Here is my code:

def hotel_cost(days):
    return 140 * days

def plane_ride_cost(city):
    if city == "Charlotte":
        return 183
    if city == "Tampa":
        return 220
    if city == "Pittsburgh":
        return 222
    if city == "Los Angeles":
        return 475

def rental_car_cost(days):
    cost = days * 40
    if days >= 7:
        cost -= 50
    elif days >= 3:
        cost -= 20
    else:
        return cost

def spending_money(money):
    return int(money)

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)


#2

@chipace87443,
As Python uses indentation
as a code-block-indicator
if you write your code
like

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)

the print-statement will be interpreted as being part of the trip_cost() function

You should try it
by using

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)

#3

why are you returing cost in else condition ??
so your function ( rental_car_cost) have to return cost in all condition ( if .. elif .. and else )
also try what @leonhard.wettengmx.n say !!


#4

It worked like that I dont know why I didnt do it before thank you!!


#5

Well... Because to me, the else condition would imply that if neither of the conditions above are true, the cost that will be returned will be the full cost without any discount.


#7

so if the days >=7 , you don't return the cost ??

i did try your code , this is the output error :


#8

@chipace87443,
@azazaz was correct in asking.....
as your code should have been

rental_car_cost(days):
    cost = days * 40
    if days >= 7:
        return cost -= 50
    elif days >= 3:
        return cost -= 20
    else:
        return cost

OR

rental_car_cost(days):
    cost = days * 40
    if days >= 7:
        cost -= 50
    elif days >= 3:
        cost -= 20
    #End of the IF ELIF:
    # =cost= now has its proper VALUE
    return cost

#9

I'm sorry. You are right, however when I tried after the correction from Leonhard it was right? I suppose I posted the wrong code or it was accepted even when this is wrong. But thank you for showing me my error and helping me!! Very kind of both of you


#10

I've got it thanks very much, i have been trying to solve this for so long