7. Plan your trip


#1

I don’t know what I did wrong. Here’s my code:

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

And I get this:

Traceback (most recent call last):
  File "python", line 20, in <module>
  File "python", line 19, in trip_cost
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'

#2

In absence of a return value,

rental_car_cost(days) + ...

looks like,

None + ...

#3

Thank you, I fixed it.


#4

A post was split to a new topic: 7. plan your trip


#5

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