5/7 why does this work

#1

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):
cost = days * 40
if (days) >= 7:
cost -=50
return cost
elif (days) >= 3:
cost -=20
return cost
return cost
def trip_cost(city,days):
return plane_ride_cost(city) + rental_car_cost(days) + hotel_cost(days)

defining hotel_cost(nights) won't work it demands that I use hotel_cost(days) but that variable is set to something else how can this work how am i calling hotel_cost with the variable for an function meant to calculate something entirely different I understand that the (days) variable is user input but it is set to be * 40 not the 140 needed for the nights in the hotel now assuming that is just replacing (nights) with (days) by some bizarre stroke of god then how can we get the car_rental_cost in the sum if the sum of the car rental is actually in cost as defined

and why am i being forced to put in return cost twice

#2

The variable can be changed as long as it remains the same within like the one use of the function.
sorry if that doesn't really make sense to you, this is my second day coding so I don't know too much, but the variable for hotel_cost() can be anything you change it to.
It's a variable, it varies.

#3

Function syntax is really weird at first. The parameter (the thing in the parentheses) can be anything --- it's really there just to let us know how many arguments/variables it takes in order to work properly. Sometimes it's named to make it clear what kind of item goes there, but sometimes that just makes it more confusing.

This is a pertinent example:

``````def lover(x):
return 'I love ' + x
def hater (x):
return 'I hate ' + x
def schizo(a, b):
print lover(a)
print hater(b)

lover('Phil')
hater('Jane')
schizo('Phil', 'Jane')``````

In the functions lover and hater, the parameters are both x, but in schizo, those same variables are plugged into a and b.

I find it helps to plug my code into this website Visualize Python. When you hit 'Visualize Execution', it shows you what variables are assigned where, step by step.
``print trip_cost('Pittsburgh', 3)``