Pull it Together


#1

def trip_cost(city, days):
def trip_cost(days):
return days
def trip_cost(nights):
return nights
def add (a,b):
return days + nights

can any on help me in solving this program.
when i click on save&submit it showed me like this

Oops, try again. hotel_cost(1) returned 280 instead of the correct value 140


#2

Please explain why there are three of these?


#3

it has given in the instructions. so as example given above i followed it.

can you suggest correct format program.


#4

For the first phase of this new function, we are to pass city and days only.

def trip_cost(city, days):

The call to the function will look like,

print trip_cost("Tampa", 3)   # for example

Inside the function we call the other three functions and pass the appropriate argument to each.

hotel_cost(days)
rental_car_cost(days)
plane_ride_cost(city)

They will all be added up and returned. Give it a try.


#5

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

#6

i got same message when i modified my program


#7

Then that would mean there is an error in the hotel_cost() function.


#8

Oops, try again. hotel_cost(1) returned 280 instead of the correct value 140

This is error that i had got when i click on save&submit.


#9

Please show us the code you have for hotel_cost. Thanks.


#10

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


#11

May we have a look at your hotel_cost function, please?


#12

def hotel_cost(nights):
hotel_cost = 140 * 2
return hotel_cost

def plane_ride_cost(city):
if city == "Charlotte":
return 183
if city == "Tampa":
return 220
if city == "Pittsburgh":
return 222
if city == "Los Angeles":
return 475

def rental_car_cost(days):
cost = 40 * days

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

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

this is my entire program.

#13

There is your culprit.

hotel_cost = 140 * 2

It should be the argument in the nights parameter that gets evaluated.

return 140 * nights

Now hotel_cost(1) will be 140.


#14

A post was split to a new topic: Where am I going wrong?


#15

i am getting same when i click on save and submit

def hotel_cost(nights):
hotel_cost = 140 * 2
return hotel_cost

def plane_ride_cost(city):
if city == "Charlotte":
return 183
if city == "Tampa":
return 220
if city == "Pittsburgh":
return 222
if city == "Los Angeles":
return 475

def rental_car_cost(days):
cost = 40 * days

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

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

This is my program could u tell me where i did wrong.

#16

You have still not fixed this function. That's where the problem has been all along. Plesse see my previous reply.


#17

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