Hey, You Never Know!


#1

Will anyone tell me whats wrong?
i get this error
trip_cost('Charlotte', 8, 0) raised an error: unsupported operand type(s) for -: 'str' and 'int'

my code:

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):
if days >= 7:
return 40 * days - 50

elif days >= 3:
    return 40 * days - 20

elif days < 3:
    return 40 * days

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


#2

Hi @ace_lebron ,

This is your trip_cost function ...

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

Codecademy tests your function, based on the assumption that you have the parameters in this order: city, days, spending_money. Instead, you have them as days, city, spending_money.
The function should be revised, as follows ...

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

#3

@ace_lebron,

You defined your trip_cost definition
as having 3 parameter days, city and spending_money

Then in the call of your trip_cost =function=
you make the mistake of providing the arguments in the wrong order......

You used

trip_cost('Charlotte', 8, 0)

which should have been

trip_cost(8,'Charlotte', 0)

But as you are using the return statement in the trip_cost =function=
will return a number Value without Display.

The solution

print( trip_cost(8,'Charlotte', 0) )

===================================

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

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

#trip_cost('Charlotte', 8, 0)
print( trip_cost(8,'Charlotte', 0) )

#4

Thanks For replying, But i am still getting the same error.

Here is my code:

   def trip_cost(days, city, spending_money):
             return rental_car_cost(days) + hotel_cost(days) +\
             plane_ride_cost(city) + spending_money
   print trip_cost(8,'Charlotte', 0)

i Have tried everything, indented the code,change the order but nothing works :weary:


#5

@ace_lebron,

Please follow the advise of @geomaticmashups,
as you will have to pass the Code-Checker tests....


#6

That's a complete answer

def hotel_cost(days):
return 140 * days
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 = 40 * days
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost
def trip_cost(city, days, spending_money):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money
print trip_cost("Los Angeles", 5, 600)


#7

@renatb,

As a learning experience
Please re-edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697


#8

IT WORKED
Thankx You Very Much <3