Transportation (Only Question why is it so)


#1

Hello,

Im a little bit confused because i thought it will work that way too

I had it like that:

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

but that was wrong cause i aint made the returns for if and elif..

But why do i need to do that, when i return at the end?

Or is it like, without return, it wont save the cost in if and elif?

Thanks for the answers, just wanna learn eheh


#2

i would work, but this:

cost - 20

won't update cost, look:

i = 10
print i # 10
i + 5
print i # 10
print i + 5 # 15
print i # 10
i = i + 5
print i # 15

see? we can temporary add (or subtract) a value from a variable, like you do here:

cost - 20

you don't store the result of this subtraction somewhere (not updating cost)

hope this helps


#3

Ah now i get it, Thanks for the fast answer, u the best :smiley:


#4