Taking a Vacation Transportation


#1

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

Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days

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

Oops, try again. It looks like rental_car_cost returns 120 instead of the correct amount (100) for 3 days.

I dont know what i miss.Can somebody debug me?


#2

a function ends the moment a return keyword is reached, so the second approach isn't really great

you should store the total cost of renting a car (days * 40) in a variable, then apply discount, and return the total cost

also, take a look at this code:

i = 10
print i // 10
print i - 5 // 5
print i // 10
i = i - 5
print i // 5

now look at how you apply discount


#3

TY for your fast reply!

I think I've understand the first half of your post.

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

Oops, try again. It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days

But I guess I still dont know what you suggest in the second half, sir.
Cant see a connection between this printing thing and my doing-nothing function unfortunately.


#4

the print statement where just to show, you didn't update total.

you should return total in all cases, not only when the car is rented between 3 and 7 days (hint: indention)


#5

Oh, I got it.Tricky one but must say I have learned few important things.Ty once again.


#6

if you need more help, post an updated version of your code


#7

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