Help needed showing error and also y do we have to retrun cost in the end?


#1





Replace this line with your code.


#2

Your indentation is off. Start your rental_car_cost(days) function on the same level as others.

def rental_car_cost(days):
    cost = days*40 #Cost per day rental is $40
    if xxxxx:
        xxxxx
    elif xxxx:
        xxxx
    return cost

The return cost is to return the initial * cost = days*40* when both if and elif do not fulfill the conditions set in them. So, you may not need the else statement.

I hope this helps! :wink:


#3

but we have already made returns through if and elif?????


#4

Oops! I should have explicitly stated that - although I did in my sample code. Now, those conditions could be seen as discounts. The number of days determine the discount. So, you shouldn't have a return on the if and elif block. And no need for an else too (Stated this before).

Once again,

def rental_car_cost(days):
    cost = days*40 #Cost per day rental is $40
    if xxxxx:
        xxxxx
    elif xxxx:
        xxxx
    return cost

Please, be guided of your elif. The instruction says "Alternatively (elif), if you rent the car for 3 or more days, you get $20 off your total." So, you should have the condition as

elif days >= 3:

I hope this clears it. :wink:


#5

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