Did you create function a called rental_car_cost?


#1

Need help, been rearranging the code in a ton of ways and it still asks the same question.


#2

Use the argument 'city'in if sentence.


#3

I fixed all of that but that is not my problem, my problem is the rental_car_cost


this is my problem now


#4

There is something wrong with the white space in your code. Try only using spaces to indent, no tabs. There should not be anything in your code that's not indentet either 0 spaces, 4 spaces, 8 spaces, and so on.

If you are still having problems try posting your code as text and format it with the </> button (mark the code and then press the button).


#5

thanks, that's what was up.


#6

@meganinja60470
similar problem here code:

def hotel_cost(nights):
    return 140*nights
def plane_ride_cost(city):
    if city=="Charlotte":
        return 183
    if city=="Tampa":
        return 220
    if city=="Pittsburgh":
        return 222
    if city=="Los Angeles":
        return 475
    def rental_car_cost(days):
        days_cost=40
        if days == 7 or days > 7:
            days_cost=days_cost*days
            days_cost=days_cost-50
            return days_cost
        elif days == 3 or days > 3:
            days_cost=days_cost*days
            days_cost=days_cost-20
            return days_cost
    rental_car_cost(8)

And I am getting the same error as you in the first post.


#7

what i did was retype all of my code and made sure I did not indent with tab at all.

From what I see here is from line 14 to 21 the if's and elif's do not line up with the others above the code, I suggest you get rid of lines 14-21 and retype them but make sure all if statements line up.


#8

new code:

def hotel_cost(nights):
    return 140*nights
def plane_ride_cost(city):
    if city=="Charlotte":
        return 183
    if city=="Tampa":
        return 220
    if city=="Pittsburgh":
        return 222
    if city=="Los Angeles":
        return 475
def rental_car_cost(days):
    days_cost=40
    if days == 7 or days > 7:
        days_cost=days_cost*days
        days_cost=days_cost-50
        return days_cost
    elif days == 3 or days > 3:
        days_cost=days_cost*days
        days_cost=days_cost-20
        return days_cost
print(rental_car_cost(1))

New error:
Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days. and it does return none


(Transportation) incomplete
#9

here is my code

I don't think that day_cost should equal 40 instead it should equal the amount of days*40, you should trim down your code you can say the same with less lines of code.


#10

You are missing an else branch for your if-elif ladder. That else branch has to account for days less than 3. Like this:

else:
    return days_cost * days

Also, instead of:

days_cost=days_cost*days
days_cost=days_cost-50
return days_cost

you should do:

total_cost = days_cost * days
total_cost = total_cost - 50
return total_cost

doesn't change the way the program works. But makes the variable names clearer. days_cost is the rate per day. So, let it remain that way. Use a new total_cost to store the total cost for some days.


#11

Is this what you mean?

    return 140*nights
def plane_ride_cost(city):
    if city=="Charlotte":
        return 183
    if city=="Tampa":
        return 220
    if city=="Pittsburgh":
        return 222
    if city=="Los Angeles":
        return 475
def rental_car_cost(days):
    days_cost=40
    if days == 7 or days > 7:
        total_cost = days_cost * days
        total_cost = total_cost - 50
        return total_cost
    elif days == 3 or days > 3:
        total_cost = days_cost * days
        total_cost = total_cost - 50
        return total_cost
    else:
        return days_cost * days
print(rental_car_cost(3))

Although now the the error says:
Oops, try again. It looks like rental_car_cost returns 70 instead of the correct amount (100) for 3 days.
Did I program my math wrong?


#12

Discount in the elif branch should be 20 not 50.


#13

It worked thank you!