Plan a vacation:Oops, try again. Oops! Did you accidentally delete the trip_cost function?


#1

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

I am unable to identify error in this code.I don't find any bug in that.Help me.


#2

your code has a few indention errors, both trip_cost and rental_car_cost shouldn't be part of the plane_ride_cost function, change the indent so the functions are after each other.

the function call:

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

should be after the after function, not part of the function.

your rental_car_cost only returns if the car is rented between 3 and 7 days. the cost should always be returned (with the necessary discount). Maybe change the indent of return cost?


#3

Thank you.It works but now I am facing this error, Oops, try again. trip_cost should take exactly three parameters: city, days, and spending_money (in that order).


#4

i already covered that?

if more problems persist, post an updated version of your code


#5

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

#6

okay, what don't you understand the problem i am trying to bring to light in your rental_car_cost function?


#7

Okay, got it.My code is working now.Thank you :slight_smile:


#8