Plan Your Trip!


#1

idk whats wrong, it says that trip_cost function was deleted...

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
    else:
        return "Not Really"

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

def trip_cost(city,days,spending_money):
    
    return trip_cost (plane_ride_cost(city) + hotel_cost(days) + rental_car_cost(days) + spending_money)
    
     print trip_cost("Los Angeles",5,600)

#2

Maybe it wasn't deleted. Maybe it wasn't created in the first place. Try using it, test your code.


#3

I've tried in sublime text 2 and the gives error in the same line, 29


#4

Python doesn't have any such error, so it must be saying something else!
(Also, that's just a text editor, not a Python interpreter!)


#5

any suggestion of which i could use?


#6

Python interpreter? Well if you're running it then you have one. But it isn't sublime text. sublime text may be invoking it, but that's something else.

Read that error of yours. Provided that you posted the very same code that you are dealing with, then the error is pretty clear on what needs changing. They are there to tell you what went wrong, they are there to help.


#7

you have to add more code in!!

city_prices = {
"Charlotte": 183,
"Pittsburgh": 222,
"Tampa": 220,
"Los Angeles": 475
}

def hotel_cost(nights):
return 140 * nights

def plane_ride_cost(city):
return city_prices[city]

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

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))


#8

def trip_cost(city,days,spending_money):

**return trip_cost (plane_ride_cost(city) + hotel_cost(days) + rental_car_cost(days) + spending_money)**

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

seems you have placed a right closing parenthesis after the spending_money variable. Remove the parenthesis and execute the code


#9

For the below code its not printing the output. It shows an error "It looks like nothing was printed to the console!"
Can anyone help me on 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
else:
return "None"
def rental_car_cost(days):
cost = 40 * days
if days >= 7:
cost -= 50
return total_cost
elif days >= 3:
cost -= 20
return total_cost
else:
return 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)


#10

you should return the value of cost not the total_cost

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


#11

I changed it according to what you told, but still the same error exists.


#12

remove the above else part. It is not required. Follow the indentation correctly


#13

Thanks finally got it!


#14

No problem It's was my pleasure..