4/7 Transportation


#1



I wanna know why in the fnction "renatl_car_cost" we use "-=" instead of just "-".And by that having a different return


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
    return cost


#2

cost -= 50 is same as cost = cost - 50


#3

Then why when i change it to just "-" it doesnt work.Says "Oops, try again. rental_car_cost(3) returned 120 instead of the correct value 100"


#4

Because - doesn't update the value.


#5

cost - 50 is not the same as cost -= 50 or cost = cost - 50

you need to use cost -= 50
or cost = cost - 50


#6

Why isnt it he sane?And why use cost = cost - 50?


#7

Why use -? It doesn't work.

Why isn't it the same? Ask the creators of Python?

Why isn't apple called a red pear? Because it isn't.


#8

lets say cost is = 100
cost = cost - 50 or
cost = 100 - 50, cost is = 50 now

same goes for cost -= 50, its just shorter

cost - 50 just don't apply value


#9

Ok.Thank you a lot.:stuck_out_tongue: