Taking a Vacation Pull it together Need help


#1



Oops, try again. trip_cost('Charlotte', 0) returned False instead of the correct value 183


Replace this line with your code. 
 def hotel_cost(nights):
    return 140*nights
    
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
    
#rental car per day     
def rental_car_cost(days):
    rent = days * 40
    if days >= 7:
        rent -= 50
    elif days >= 3:
        rent -= 20
    return rent      
    
def trip_cost(city, days,):
    return sum== plane_ride_cost(city) +rental_car_cost(days)+hotel_cost(days)

Hey guys, I got stuck with this part of the exercise. This code returns nothing but only this error message I described above. Could you please write me, what exactly with this code wrong?

Thanks in advance =)


#2

You can not do this.

return the statement itself. Remove sum==


#3

Do not use sum as a variable name because one of Python's built-in functions is sum().

Also, replace the comparison operator (==) with assignment operator.

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

#4

I get an error with line 0 (which I can't do anything about...)
Can someone help?

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


#6

Thank you very much, now it works!


#7

write your code, it´s difficult to help without seeing it


#8

Glad that I could help :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

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

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


#10

Hi! The unexpected EOF (End Of File) error seems to be raised here:

Remove that line.

I hope this helps! :wink:


#11

Works now, thanks! Can’t believe I was stuck on that for nearly two years... -_-


#12

You're welcome.

Have fun coding! :wink: :smile:


#13

def hotel_cost(days):
return 140* days

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):
rent = 40* days
if days >= 7:
rent -=50
elif days>= 3:
rent -=20
return rent
def trip_cost(city,days):
return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)

The correct code for this program


#14

This is what I have - not sure what is wrong.

def hotel_cost(nights):
return 140*nights

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

rental car per day

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

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


#15

I get the error: "looks like rental_car_cost returns 120 instead of the correct amount 100 for 3 days".
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):
return 40 * days
if days >= 7:
return 40 * days - 50
elif days >= 3:
return 40 * days - 20


#17

Indeed, this function is faulty.

you had returned the function too early, with

and will not see the other conditions appended. Return the function at the end of that function or create an else, for when all the above fails.

I hope this helps.

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

I hope this helps! :smile:


#19

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

pls tell me the error here


#20

It's because of the indention


#21

Yes, it most certainly helped, but I don't understand how I would have or should have known that the "return 40 * days" was called too early. what's the rule of thumb?


#22

Whenever a return is used, at a particular level in your code, it terminated the process there and moves to the next.

In your case, the function had other conditions it needed to check, and where they all fail, it should end/return it on the initial idea of the function. Now, for the subroutines, if and elif, they each have return statements to say that that is where it ends if condition is fulfilled. You could look at return statement here.


#23

Hi everyone! I am a completely newbie

my error :

Oops, try again. trip_cost('Pittsburgh', 8) raised an error: global name 'Plane_ride_cost' is not defined

my code:

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) :
price = 40 * days

if days >= 7 :
    price = price - 50

elif days >= 3 :
    price = price - 20 

return price

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

""""Thank you!!!""""