Code problem?


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


Your code is missing a few things that the instructions said you should have one is the price variable that contains days*40

price = days*40

Having declared that variable you can modify your if and elif blocks to refer to it for example,

if days >= 7:
        price = (days*40) - 50


Although I am unsure of the exercise you're on.


cost = days*40 #Cost per day rental is $40

as a local variable in your function block, before your if block as in the instructions.

That way, you can make for a continuous iteration like: cost -= 50 in your if block and so on...


def rental_car_cost(days):
if days >= 7:
return cost = (days*40)-50
elif days >= 3:
return cost = (days * 40)-20
I am writing this code but it does not seems to work out

It show
ile "python", line 16
return cost = (days*40)-50
SyntaxError: invalid syntax



Did you check out my recommend solution?

I said to put

Just after you defined the function. Then,

if days >= 7:
return cost -= 50

and so on... Because you have already defined cost. All you need do is iterate.


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