# How can I fix this code and why would it not work?

#1

Hey, I am doing this section and when I enter in my code, I get "None" however Codecademy tells me "Oops, try again. trip_cost should take exactly 2 arguments!"

Should it not just let it work if it does? I can't think of any other arguements!

``````def hotel_cost(nights):
return nights * 140

def plane_ride_cost(city):
if city == "Tampa":
return 220
elif city == "Charlotte":
return 183
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

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

#2

well currently your trip_cost has zero parameters:

``def trip_cost():``

it should have two parameters:

``def trip_cost(parameter1, parameter2):``

look in the instructions for what the parameters should be

#4

Have you tried using raw_input so the program knows what the parameters are?

I did the following:

def hotel_cost(nights):
return 140 * int(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):
fee = 40 * int(days)
if int(days) >= 7:
fee -= 50
elif int(days) >= 3 and int(days) < 7:
fee -= 20
return fee
nights = raw_input('How many nights are you going to sleep in hotels? :')
city = raw_input('Which city do you want to visit? :')
days = raw_input('How many days do you need a car? :')
print hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)

I used the int() function so the calculations would come out right, else the values were just taken as strings and everything would be messed up

#5

why don't cast the input directly:

``nights = int(raw_input('How many nights are you going to sleep in hotels? :'))``

saves a lot of conversions. You don't have to use raw_input, you can also provide the arguments when calling the function.

#6

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