Taking a Vacation


#1



Taking a vacation


Oops, try again.
trip_cost('Charlotte', 0) raised an error: sum expected at most 2 arguments, got 3
"""but says this same error if ran again with no changes for each city with the exception of charlotte"""


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:
        cost -= 20
    return cost

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


#2

Go look up documentation/examples for sum since it's saying you're using it incorrectly.

This isn't really a scenario where you want to use that function though, since you're not looking to sum the elements of an iterable. How else can you add numbers?


#3

these are the instructions (its says to use SUM)??

"Below your existing code, define a function called trip_cost that takes two arguments, city and days.Like the example above, have your function return the sum of calling the rental_car_cost(days), hotel_cost(days), and plane_ride_cost(city) functions.

It is completely valid to call the hotel_cost(nights) function with the variable days. Just like the example above where we call double(n) with the variable a, we pass the value of days to the new function in the argument nights."


#4

It says to compute a sum of three values. Doesn't mention the function.
You can use the function. But since the values that you wish to add are not in an iterable you would have to put them in a list or other iterable first which is just extra operations for no good reason.


#5

I've got the same problem.

My input to trip_cost is: trip_cost(num_days, city). The application finishes with the
correct results in my print statements. But I also get an Oops statement, posted beneath my code.

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

What's wrong? I input 5 days, Los Angeles. Somehow whatever tool codecademy is using as a Python interpreter is a: switching the order of the parameters, b: inserting Tampa when I input Los Angeles. Why? It happens on the next exercize as well when there are 3 parameters (including spending money.) Quite maddening! I am using the raw_input function to collect my input values, one at a time. Might that be a problem? Thanks.


#6

Here is my print statement output.

How many days total for your trip? 5
Whereabouts ya going'? Los Angeles
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.


#7

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