Can't multiply sequence by non-int of type 'float'


#1

Clicking Save & Submit Code (multiple times), produces different errors, when nothing in the code has changed.

Oops, try again. trip_cost('Pittsburgh', 5) raised an error: can't multiply sequence by non-int of type 'float'
Oops, try again. trip_cost('Tampa', 1) raised an error: can't multiply sequence by non-int of type 'float'
Oops, try again. trip_cost('Los Angeles', 1) raised an error: can't multiply sequence by non-int of type 'float'
Oops, try again. trip_cost('Pittsburgh', 1) raised an error: can't multiply sequence by non-int of type 'float'

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

def hotel_cost(days):
    return 140.00 * days

def plane_ride_cost(city):
    if city == "Charlotte":
        ride_cost = 183.00
    elif city == "Tampa":
        ride_cost = 220.00
    elif city == "Pittsburgh":
        ride_cost = 222.00
    elif city == "Los Angeles":
        ride_cost = 475.00
    return ride_cost

def trip_cost(a, b):
    return rental_car_cost(a) + hotel_cost(a) + plane_ride_cost(b)

print trip_cost(4, "Tampa")

within Eclipse or from commandline, this block of code returns the anticipated results. But from within Codecademy, I cannot get past this exercise.


#2

Look at your function,

def trip_cost(a, b):

or better as

def trip_cost(days, city):

Now look at your error,

Oops, try again. trip_cost('Pittsburgh', 5)

Notice anything?


#3

Yes and No.

I see the obvious trip_cost('Pittsburgh', 5) -- I am assuming the order is reversed. Working with more descriptive variables is preferred...agreed.

As I understand it.

  • '4' corresponds to days parameter
  • Tampa corresponds to city parameter.
  • it is permissible to reuse 'days' within the return
    definition calls.
def trip_cost(days, city):
   return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)
print trip_cost(4, "Tampa")

But don't understand beyond that. Honestly, been surfing i-net for answers and working on this one task for two days. I don't understand what I don't see.


#4

The parameter name does not matter, it is the order and the order only I was referring to. It is testing city then days when your parameters takes days then city.

See where the test is throwing a fit now?


#5

Applying what you have explained, makes the function work

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

print trip_cost("Tampa", 4)

And, now the 'working' codes is... (at least my version)

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

def hotel_cost(days):
    return 140.00 * days

def plane_ride_cost(city):
    if city == "Charlotte":
        ride_cost = 183.00
    elif city == "Tampa":
        ride_cost = 220.00
    elif city == "Pittsburgh":
        ride_cost = 222.00
    elif city == "Los Angeles":
        ride_cost = 475.00
    return ride_cost

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

print trip_cost("Tampa", 4)

But how did you know the function was testing (city, days) versus (days, city) ???


#6

This, it was told to you in the error message.