I don't know what my error is


4.(Functions) > Taking a vacation > 4.(Transportation)

Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days. But it's working for more than a day.

I expect for for 1 day to have a return of 40.

def rental_car_cost(d):
    rentcost = d * 40
    if d >= 7:
    elif d >= 3 and d < 7:


Found what my error is, it was a stupid one, I wasn't considerating rentals lasting less than 3 days.
Fixed with

    return(d * 40)


We are not asked to print anything in our function. Print the call expression, if anything.

As we can see above, cases where days is less than 3 have no return value, hence, None.

We should use the parameters given in the instructions:

def rental_car_cost(days):

If we follow the numerical order from highest to lowest we don't need to use and to test an interval.

    if days >= 7:

    elif days >= 3:

    else: # actually not needed in this instance

We can write a single return statement at the end.

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


Yeah I saw, thank you very much, I added some print to see the results.
And d stands for days, it's just shorter


You're welcome.

I had suspected as much. For future reference, remove any debugging code when posting a question. That will help avoid confusion and assumption.


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