# Pull it Together taking a Vacation

#1

def hotel_cost(days):
return days*140

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 "Try again"``````

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

def trip_cost(days,city,):

``print rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)``

Cant any one tell me why this wont work ??? !! I cant see whats wrong keep getting an error Oops, try again. trip_cost('Pittsburgh', 6) returned None instead of the correct value 1282

#2

There are two problems in the `trip_cost` function:

1. you were supposed to return the calculated value, not print it out;
2. according to the instructions the first argument is a city and the second is number of days.

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

#3

When i use that method it only returns the cost of the plane ride, it doesnt sum them all together.

#4

#5

someone pointed out i used day instead of days in the final function, thanks.

#6

## Well, I don't have any of those, yet with this:

def hotel_cost(nights):
return 140 * nights

# print "Cost is: " + str(cost)

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

# print "Cost to destination: " + dest + " is " + str(flight_trip_cost) + " dollars."

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

# print "Cost of rental car for trip is: " + str(car_rent) + " dollars."

def trip_cost(num_days, location):
print " "
print "Final tally:"
car_cost = rental_car_cost(num_days)
print "Car rental: " + str(car_cost) + " dollars."
housing_cost = hotel_cost(num_days)
print "Hotel cost: " + str(housing_cost) + " dollars."
plane_cost = plane_ride_cost(location)
print "Plane ticket: " + str(plane_cost) + " dollars."
#tally = car_cost + housing_cost + plane_cost + cash
tally = int(car_cost) + int(housing_cost) + int(plane_cost)

``print "All for a grand total of: " + "\$" + str(tally) + ".00" + " dollars."``

num_days = raw_input ("How many days total for your trip?")
location = raw_input ("Whereabouts ya going'?")

# Let's see what we're passing

print ("num_days is: %s") % num_days
print ("location is: %s") % location
trip_cost (int(num_days), location)

1. all calculations are made correctly: output

How many days total for your trip? 5
num_days is: 5
location is: Los Angeles

Final tally:
Car rental: 180 dollars.
Hotel cost: 700 dollars.
Plane ticket: 475 dollars.
All for a grand total of: \$1355.00 dollars

1. BUT, get an OOPS error, that seems random, and quite often has nothing to do with what I entered as input, except for number of parameters.

Oops, try again.
trip_cost('Los Angeles', 5) raised an error: invalid literal for int() with base 10: 'Los Angeles'.

Quite often says, Pittsburgh, or Tamp, and the second parm varies widely. Looks as if the order
of the parms is being reversed...why?

Oh, and most importantly, if I go directly to the last exercize in the lesson, everything works perfectly without any OOPS.