# Pull it all together - returned 120 instead of 100

#1

5. Pull it all together

no matter what I try it keep saying, "rental_car_cost(3) returned 120 instead of the correct value 100

``````def hotel_cost(nights):
return (nights) * 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

def rental_car_cost(days):
return (days) * 40
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 80
else:
return cost
def trip_cost(city, days):
return hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)``````

#2

HI this line

``return hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)``

you should put days instaed fo nights in teh hotel_cost()

#3

ok. I just made that change, but I am still getting the exact same error message.

#4

try to re-do the previous lesson because this part

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

isn't right

#5

ok. let me try that.

#6

can you give me a little more guidance because the step before said it is right and the current step said to add "below your existing code" so as far as I know I am following the instructions to the letter.

#7

The discount value you use in your 'elif' block is quite high, especially for someone only renting a car for 3 days!

Also, maybe double check how many return statements you have inside your rental_car_cost function. Ideally, you will only need a single return statement, which should return the total cost minus any discounts that are applied.

In fact, I'm new to Python myself, but I believe the return statement is similar to most other languages, i.e. it is used to exit a function, with an optional returned value.

If you immediately return a value, at the start of your function, the remaining lines of code will not be executed, since you have 'broken out' of the function.

This might be a bit dense for new programmers, but this is a good resource:

#8

I changed the value for 3 days and it has no effect on the error message. Do you know that that is the problem or are you just throwing out a suggestion?

also - it says the code is correct in the previous exercise and then it says add to "your existing code." It doesn't say to change (but even if I do change it - trying both to increase and decrease it - it still does not work.)

#9

Can you tell me what's not right because I have been working on it for hours with no luck - and step 4 said it is correct.

#10

can you post your new code?

#11

def hotel_cost(nights):
return (nights) * 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
def rental_car_cost(days):
return (days) * 40
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
rental_car_cost()
return cost
def trip_cost(city, days):
return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)

#12

you previously said there was a problem with the following part of my code

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

but in the previous exercise the program said I had it correct. In the current exercise it tells me not to change anything, but to add to the code so I don't see where it is wrong. (I also tried increasing and decreasing all kinds of numbers, but i kept getting the exact same error message.)

#13

Below your existing code, define a function called rental_car_cost with an argument called days.

``def rental_car_cost(days):``

then they says
Every day you rent the car costs \$40. (so for one day you will pay \$40) and if you take the car for 7 or more day you get a reduction of \$50 and if... for 3 or more days ...of \$20 .
Well since we will remove the 20 and 50 \$ to the rent_car it's better if we create a variable and save the operation

``days * 40``

like that

``````def rental_car_cost(days):
rent_car = days * 40``````

you just need to add the if , elif and else statement like you already did.. but you should remove the 20 and 50 to the rental_car variable

#14

Remove the 20 and the 50? ... ok. I just completely removed the 20 and 50 and I still get the same error message.

#16

#17

I'm going to try and prevent you guys from going too deep in this direction...

`return (days) * 40`

Please read my original comment, in its entirety, and have another look at your code. Also, feel free to follow the link, it links to a valuable resource, which might help explain why I said to be careful of how many return statements you have, since you only need one.

Keep up the spirit you'll get it soon

#18

def hotel_cost(nights):
return (nights) * 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
def rental_car_cost(days):
return days * 40
def trip_cost(city, days):
if days >= 7:
return days - 70
elif days >= 3 and days < 7:
return days - 20
return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)

#19

from you first post

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

Remove the else statement (if you look at the introduciton of the lesson you will see an example of the code how the code could be..) and you will see that there isn't a else statement so you should remove it

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

and it's not finish .. you are removing (the number that you should remove are 20 and 50 ) it from a variable you never define which is cost so this line

``    return (days) * 40``

instead of return you should save days * 40 in a variable named cost like that

``cost = days * 40``

Since it's function you should return something (back to the introduction function part.. the return statement is indent like the if and elif statement ) so you just need to add this line

``retrun cost #in cost you save days * 40 so number of day is 1 it will return cost which is equal to 40``

I hope you read what I wrote
Hint

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

#20

I figured it out. I am not quite sure what greyedfox was getting at, but that was not the issue. Thank you all for your help!

#21

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