Python working function not working

I am learning Python through codeacademy and I am stuck in this tutorial :

My code is:

def hotel_cost(nights):
    return 140 * nights

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):

    return 40 * days

    if days >= 7: 
        return days - 50

    elif days >= 3:
        days - 20 
        return days

    return days

Sorry for disabling code locks. Anyway, I get this error when I run the code: "Oh, try again. It seems that rent_car_cost returns 120 instead of the correct amount (100) for 3 days."

This tells me that this happens around elif> = 3 days: but not sure any help would be great!

+4
source share
2 answers

The logic in rental_car_costlooks wrong. To begin with, you return to the first line, all other functions will not be executed. I think you were aiming for something like this:

def rental_car_cost(days):

    cost = 40 * days

    if days >= 7: 
        return cost - 50

    elif days >= 3:
        return cost - 20

    return cost
+1

:

elif days >= 3:
    days - 20 
    return days

:

elif days >= 3:
    return days - 20 

20 days, days .

,

elif days >= 3:
    days = days - 20 
    return days

days, .

+1

Source: https://habr.com/ru/post/1610195/


All Articles