Unable to complete taking vacation


#1



Replace this line with your code.


#2

def hotel_cost(nights):
return 140 * nights
hotel_cost(5)
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 a valid city"
def rental_car_cost(days):
daily = 40 * days
if days >= 7:
daily -= 50
elif days>= 3:
daily -= 20
return daily
def days(nights):
return nights
def trip_cost(city,days):
return rental_car_cost(days) + hotel_cost(nights) + plane_ride_cost(city)
print trip_cost("Tampa",6,7)


#3

First, it would have been nice you read the forum guidelines and see how to format codes. Python for instance, is indentation sensitive.

There is an issue with your rental_car_cost function. You should be giving a discount on the price and not the days. See sample fix, and fix others.

def rental_car_cost(days):
    cost = days*40 #Cost per day rental is $40
    if days >= 7:
        cost -= 50
    #write elif here.
    return cost

Let me know if this resolves! :wink:


#4

the rental_car_cost function is totally valid, maybe the variable name isnt choosed well but everything is fine (syntax + semantic).

but you have 3 problems to solve in your code, which i post here again:

def hotel_cost(nights):
    return 140 * nights

hotel_cost(5)

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:                         #<--- not a good idea to return a string here
        return "not a valid city" #<--- (you want to sum them up later)

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

def days(nights):                 # <-- this function dont make any sense
    return nights

def trip_cost(city,days):       # <-- check the function-body, you try to call function hotel_cost with an unknown variable
    return rental_car_cost(days) + hotel_cost(nights) + plane_ride_cost(city)

print trip_cost("Tampa",6,7)      # <- your function trip_cost only has 2 parameters, 
                                  # <- but you try to call it with 3 arguments

if you have further problems, please ask a question instead of only posting code!


#7

def hotel_cost(nights):
return 140 * nights
hotel_cost(5)
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):
daily = 40 * days
if days >= 7:
daily -= 50
elif days>= 3:
daily -= 20
return daily

def trip_cost(city,days):
trip_cost = rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)
return trip_cost
here i have doubt how i can pass the nights value here ? please suggest me


#8

I honestly do not get you. What exactly is validity if the wrong variables are targeted... I believe my initial suggestion did not say that the OP's code is invalid. And continuing your suggestion should also be rightly targeted to the OP so as not to cause confusion. Well well well... Have the stage.

Thank you! :slight_smile: :slight_smile:


#9

def hotel_cost(nights):
return 140 * nights
def plane_ride_cost(city):
city = input()
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

ERROR - "Oops, try again. plane_ride_cost('Charlotte') raised an error: unexpected EOF while parsing (, line 0)"

Line 0 doesn't even exist...


#10

actually i am ask a question here that is any function that able to assign days = nights
"def trip_cost(city,days):
trip_cost = rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)
return trip_cost"
in above code u can see that in hotel_cost(days) but we already built a function called hotel_cost(nights)
so if any function is there to assign days == nights
this what i am trying to ask


#11

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