4/7 rental costs

#1

def rental_car_cost(days):
# Each day costs 40 dollars
cost = days * 40
if days >= 7:
cost - 50
elif days >= 3:
cost - 20
return cost

my code above keeps returning more than 100 for the 3 day calculaion. Why is this so?

#2

Hi, @zakmoha64,

Because your code is not formatted, it is difficult for other users to read and debug it. As code is being posted, you can format it by selecting it, and then by clicking the `</>` button above the editing area. This will enable us to see important details, such as the indentation and underscores.

This expression has a value that is `50` less than the value of `cost`, but does not successfully change the value that is stored in the variable, `cost` ...

``cost - 50``

``cost -= 50``

... or ...

``cost = cost - 50``

Check out the rest of your function for a similar issue.

#3

Wow good looking my friend... I was having the same problem. Was fixed by adjusting the variable

#4

This returns none for one day and I can't figure out why. Everything looks right to me? Thanks in advance.

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

#6

Use the below code. It should be rental_car_cost instead of cost.

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

return rental_car_cost``````

#7

thank you very much. one more question, what is the difference between the minus by itself and the minus and equal sign together?

#8

Well

-= means deducting the cost of 50 from the total cost if days is = or > 7
Else cost = cost - 50 is one & the same.

#9

Thanks a bundle! ^-^