Stuck on 5/7


#1

What is wrong with my trip cost? It keeps giving me the error "hotel_cost(1) raised an error: unexpected EOF while parsing (, line 0)"

My Code:

def hotel_cost(nights):
nights = input("please enter the amount of nights your here")
140 * nights
return 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:
cost -= 20
return cos

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


#2

When defining a function with parameters the parameters will have a value when they are called.
In your case you gave hotel_cost(nights) a parameter called nights. Anytime you use the variable nights inside that function it will have the value which it was called with. So hotel_cost(1) means that inside that function nights will have the value 1.
You have then given nights a new value by asking the user to input the number of nights.
This should work in a normal program but with codecademys testing it will not work if it shouldn't be there. Just remove the input.

Also after that you have

140*nights
return nights

this will not work either cause nights has the value of 1. You could do nights = 140*nights then return nights. Or just return 140*nights


#3

this is what I did and it worked :smile:
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):
total = days * 40
if(days >= 7):
total -= 50
elif(days >= 3):
total -= 20
return total
def trip_cost(city, days):
return rental_car_cost(days)+hotel_cost(days)+plane_ride_cost(city)