Plan your trip


#1

hi everyone,

the task is asking:

After your previous code, print out the trip_cost( to "Los Angeles" for 5 days with an extra 600 dollars of spending money.

Don't forget the closing ) after passing in the 3 previous values!

it is not printing anything,

this is the message that I get "Oops, try again. It looks like nothing was printed to the console! "

I checked after the hint: "You'll want to print the result of calling trip_cost with the above values as arguments! Your final call should look something like: print trip_cost("SOME CITY", NUM_DAYS, SPENDING_MONEY)" but it is what I thought I wrote.

thank you for your help


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


#2

Your code is okay except last line.

1.Indent it properly. (0 indentation)
2.Capitalize the L of los Angeles


#3

how I should indent?


#4

Same level as of your rest of your code! (make it slide to very left aka 0 indent)


#5

thank you very much for your help


#6

Hi,

I have the same error, after removing indentation i get this TypeError: cannot concatenate 'str' and 'int' objects


#7

Hi @guykande, Can you post your code here ?


#8

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


#10

trip_cost() is a function that takes 3 arguments, What I mean is that you have to pass 3 arguments to it and separate them using commas.

like this..

trip_cost(x,y,z)
not
trip_cost(x+y+z)


#11

you are a star dude. Thanks i was lost....


#12

One more thing ,no need to check if days are less than 7 (the code below)

elif days >= 3 and days < 7:

As it comes lower in flow control just
elif days >= 3 : will be suffice.


#13

i see, well noted let me check.


#14

hi friends ,

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

but the error message is only the last line print trip cost is not working.. nothing is printed in the console


#15

the highest order has 0 spaces from left,1st order gets 4 spaces from left and 2nd order gets 8 spaces from left. If u use text editor for programming then u wouldn't need to indent on ur self here's an example:
def name():
1234if something:
12345678return something
1234elif somethingelse:
12345678return somethingelse
1234else:
12345678break


#16

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