Need Explanation of Why We Use +=/-=....Is is because we need to use lists?


My code is actually behaving correctly- I knew I had to write it this way because of the example given on the page. I do not understand why we need to use the "+=" and the "-=" in the transportation (car rental cost) section.

Is this because we need to make this into a list? Is do we need to direct the computer to maintain the cost argument before altering it? I'm not sure why we can't simply write cost - 50 or cost - 20? Why is this so?

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 = days * 40
    if days >= 7:
        cost -= 50
    elif days >= 3 and days < 7:
        cost -= 20
    return cost


Hi the

cost -= 50

is the same as

cost = cost - 50

the same for +=


Thank you! To clarify, to make I am understanding this 100%....

By using the -= and the += in this instance, I am merely telling python that it should look at this line of code as though cost is actually on either side of the operator? This is the shorthand way to do it?

Thank you so much!


This is the shorthand way to do it?


You're amazing. Thanks!


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