PLAN YOUR TRIP not printing the correct value plz help


#1

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:
        return cost-50
    elif days>=3:
        return cost-20
    return cost
def spending_money():
    return spending_money
def trip_cost(city,days,spending_money):
    return hotel_cost(days)+plane_ride_cost(city)+rental_car_cost(days)+spending_money
print trip_cost("Charlotte",8,500)

this is my code but its not printing the correct value its printing 2073 instead of 1955
please help


#2

Your 2nd if/elif is wrong.

Here's the code for it:
def rental_car_cost (days):
if days < 3:
return 40 * days
elif days > 6:
return 40 * days - 50
else:
return 40 * days - 20

That should do it.


#3

I think my if/elif is correct but now there is some other problem
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:
return cost-50
elif days>=3:
return 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 Angleles",5,600)

its showing the following error:
Traceback (most recent call last):
File "python", line 21, in
File "python", line 20, in trip_cost
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'


#4

i disagree with @nilswanicki suggestion. your rental_car cost is fine

You should indeed go to Los Angeles for 5 days, but then it is important to spell Los Angeles correctly here:

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

otherwise, plane_ride_cost will return None (the default) and that will cause an error (None type + integer)


#5

oh yeah right thanks i didn't look that i had made a typo


#6

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