#7 Plan your trip! "city, days, and spending_money (in that order)"


#1

I've been staring at this:
°
°
°

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

#  ... which gets this error message: Oops, try again. trip_cost should take exactly three parameters: city, days, and spending_money (in that order).

What am I missing?


#2

Ensure that rest of your code does not have any goofiness in it. Meaning good indentation no open if/else or loops.

MY code Example: 7/7

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

#3

Hi zeziba, thank you for looking at it. The rest was automatically carried over from the previous "way-to-go" page. Should be okay, no?


#4

Here is all my code on this page:

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

#This is the error message: Oops, try again. trip_cost should take exactly three parameters: city, days, and spending_money (in that order).

Help would be much appreciated.


#5

Still stuck here :hourglass_flowing_sand:


#6

Make your print line up with the def then it should work


#7

Thanks malthael, but I had already tried that. Tried again, just in case. That way (with the print lined up with the def) I get a different error message, this:

Traceback (most recent call last):
File "python", line 25, in
File "python", line 23, in trip_cost
TypeError: 'int' object is not callable


#8

Read your error message it is telling you what to fix right there.

Put that on it's own line to or you will get some recursion going on.

EDIT:

I guess you wouldn't you have a return above it, it should never get to that line.


#9

If it's not obvious, this should tell you more!


#10

zeziba, I'm afraid I don't know what you mean. Nothing is obvious to me here.

The part above the print line (i.e. down to and including line 23) is of course unchanged from the page before, where it worked fine. So, what's the logic of python complaining about it now, mewonders.


#11

What zeziba is trying to say once you drop both of those parentheses, your code should run just fine, and don't indent the print line


#12

Success!!!
That was it. Because spending_money isn't a function. Now it's obvious. And I had just made that same mistake before.

The thing is working now, and this is how it looks:
°
°
°
def trip_cost(city, days, spending_money):
return plane_ride_cost(city)+hotel_cost(days)+rental_car_cost(days)+spending_money

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

I thank you all


#13

def hotel_cost(nights):
night_cost=140*nights
print night_cost
return night_cost
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 "Your City is not in our list"

plane_ride_cost("Tampa")

def rental_car_cost(days):
rental_car_cost=40
s=rental_car_cost(days)
print s
if days>=7:

    rent_amount=(rental_car_cost*s)-50
    print rent_amount
    return rent_amount
elif days>=3:
    rent_amount=(rentl_car_cost*s)-20
    print rent_amount
    return rent_amount
elif days<=1:
    rent_amount=rental_car_cost
    print rent_amount
    return rent_amount

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

Can you tell where I have done mistake


#14

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

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

Def trip_cost(city, days,spending_money): WILL WORK
def trip_cost(days, city, spending_money): does not work..
WHY?


#15


#16

Héy Men,
This is your code for solve this step:
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 False
def rental_car_cost(days):
amount = 40 * days
if days >= 7:
amount -= 50
elif days >= 3:
amount -= 20
return amount
print rental_car_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)


#17

Guys, though your code is perfect, don't forget to space them accordingly. Indentation is a ■■■■■!


#18

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

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

def hotel_cost(nights):
# print (140*nights)
return (140*nights)

def trip_cost(city,days,spending_money):
total=(hotel_cost(days)+plane_ride_cost(city)+rental_car_cost(days)+spending_money)
print total
return (hotel_cost(days)+plane_ride_cost(city)+rental_car_cost(days)+sepnding_money)
trip_cost("Tampa",10,100)

this is my program but it shows error
2070
Traceback (most recent call last):
File "python", line 27, in
File "python", line 26, in trip_cost
NameError: global name 'sepnding_money' is not defined


#19

that totally did it for me... thanks!


#24