Lesson 7/7 Taking a Vacation


#1

Super confused because one lesson it tells me I’m doing it right, and then the next one I’m getting these errors. Need help!

Traceback (most recent call last):
File “python”, line 25, in
File “python”, line 23, in trip_cost
File “python”, line 15, in rental_car_cost
NameError: global name ‘rental_cost’ is not defined

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

#2

First thing to be looking for, one would suppose.

Remember, assignment is different from comparison.


#3

You put rental_cost == days * 40
It is supposed to be rental_cost = days * 40
It is different.
Same with all your other ones with rental_cost.


#4

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