Transportation Help


#1



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

Oops, try again. It looks like rental_car_cost returns instead of the correct amount (40) for 1 days.


Replace this line with your code. 
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):
    cost = 40 * days
    if days >= 7:
        cost -= 50
    elif days >= 3:
        cost -= 20
    else:
        return rental_car_cost


#2

your return the function, you should return the cost

make sure that you return cost also after you applied discount


#3

In your function, you return rental_car_cost. This variable holds the function itself, maybe you meant to return the variable cost?

Also, the body of an else clause only executes when none of the conditions in the if or elif statements above are true. For example, in the following code, "Hooray!" is only printed when x is not 5 and x is not 10. If x is either of those values, then "fiver" or "dime" are printed out instead. Regardless of the value, only one print statement ever happens.

if x == 5:
    print("fiver")
elif x == 10:
    print("dime")
else:
    print("Hooray!")

#4

In this rental_car_cost you specified elif condition whcih can be suffice if days are greater then 7 in which they will give both the discounts. I think we have to give a range whcih suggest more then 3 but less then 7. Please correct me if wrong.

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

#5

Return both the total and the cost at the end of the code to make it work.
@ge02137


#6

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