Transportation Issue


#1

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

Error Message: Oops, try again. rental_car_cost(3) returned 120 instead of the correct value 100

I really need this help to proceed


#2

Do you agree with the error message?
If you read your function, if you execute it manually, in your head, what does rental_car_cost(3) then evaluate to? If you got the wrong answer (100) then you have understood your code correctly and should compare it with what it should be doing to get the correct result. If you got the correct result (120) then you've misunderstood your code and you might want to explain what you think it does so that someone can point out where you're going wrong.
You'll also want to take care to post code that is intact so that there is no doubt about exactly what your code looks like, to ensure that other people are seeing the same code as you're having trouble with and to make it easy, inviting for others to help out.


#3

I had the problem with the same error message but then I modified the code like this:
def rental_car_cost(days) :
cost = 40*days
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost

And it is working :slightly_smiling:


#4

I literally copy-pasted that into my code, intended what I had to intend, and it doesn't work.


#5

I have tried this code a few different ways and it doesn't seem to work. I've been working on it for 2 days with no resolve.

I've even copied and pasted code that peoplehave posted as working and either get an error that I'm getting 120 instead of 100 or that there is a syntax error after my if statement. any help would be appreciated


#6

Hi can you post your code ?

here how to format it


#7

here is the latest code I've tried:

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

And here is the error I get:

File "python", line 14
if days >= 7:
^
IndentationError: unindent does not match any outer indentation level


#8

like the error says its a indent problem you code should be like that

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

#9

I've tried that and when I do I get this error

Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days

I even erased what I had wrote in and copied and pasted the code you just posted and got the same error.


#10

now you shoud add return cost this will be in case you rent the car just for one day its should be indent like your if and elif statement like that

    elif days >= 3:
        cost -= 20
    return cost

#11

Thank you very much! that seems to have been my problem. Once I added that it worked. Thank you for your help and I'm sorry for the dumb question


#12

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

i've been trying all that's been said and it still tells me "It looks like rental_car_cost returns 120 instead of the correct amount (100) for 3 days." what am i doing wrong?


#13

You have two return statements that's whats giving you the problem. Take a look at your code and the code below.

cost = days * 40
if days >= 7:
cost -= 50
elif days >= 3:
cost -= 20
return cost

#14

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