7/7 Plan Your Trip - I don't know what's wrong


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/taking-a-vacation/exercises/plan-your-trip?action=lesson_resume&link_content_target=interstitial_undefined

<In what way does your code behave incorrectly? Include ALL error messages.>
Traceback (most recent call last):
File “python”, line 27, in
File “python”, line 25, in trip_cost
TypeError: unsupported operand type(s) for +: ‘int’ and ‘NoneType’


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

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

print trip_cost("Lost Angeles", 5, 600)


#2

here:

print trip_cost("Lost Angeles", 5, 600)

you made a typo in Los Angeles, as such, the plane_ride_cost function returns None (the default returned by a function), and then in trip_cost None (returned by plane_ride_cost) + integers gives an error.


#3

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