TAKING A VACATION : Pull it Together | Code is not running as expected


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

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


print(trip_cost("tampa", 7))

Output of the code:

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

Where is the problem in the code? I don’t understand ! Help!


#2

here:

print(trip_cost("tampa", 7))

tampa is not a valid destination, as such, the function doesn’t return an integer, instead it returns its default value (None). None + integer results in an error as you have seen


#3

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