Why does this code work?

#1

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
else:
return 0``````

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

def trip_cost(city, days):
return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)

Two questions.
What does it mean with amount -= 50? If days >= 7, subtract or... equals 50 dollars? Couldn't I just put a -?

Also, why does the call (days) work with hotel_cost if (nights) was used in the original function? I didn't get the example in the instruction window.

#2

First -= is how you do subtraction when you are taking away from a current variable.
second calling it with days just changes all the things that say nights to days since they are the same number.

#3

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