Not able to resolve this error


#1

def hotel_cost(days):
return 140 * days 

def rental_car_cost(days):
cost = 40 * days

if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost

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 trip_cost(city, days):
return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)

This code is giving me error - File "python", line 4
def rental_car_cost(days):
^
SyntaxError: invalid syntax

Not sure where I am going wrong


#2

Your indentation needs to be corrected... Make sure all blocks are proper.

def hotel_cost(days):
  return 140 * days 

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

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 trip_cost(city, days):
  return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)

Following each colon, everything that is a part of the block is indented at the same level.


#3

I am doing something like this,

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

nights = 6
days = 7
city = "Tampa"
total = hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)

print trip_cost(total)