8. Taking a Vacation


#1



8. Taking a Vacation


It returned 120.


I expected it to return 100.


def hotel_cost(nights):
    return 140 * nights
def plane_ride_cost(city):
    if city == "Charlotte":
        return 183
    elif city == "Pittsburgh":
        return 222
    elif city == "Tampa":
        return 220
    elif city == "Los Angeles":
        return 475
def rental_car_cost(days):
    return days * 40
    if days >= 280:
        days - 50
    elif days >= 3:
        days - 20
    return days


#2

Hi 5k33t! The error is because the code ends on the first return line:

return days * 40

So when counting the 3 days performs the multiplication but fails to get to execute the comparison instance to make the discount. The correction to your code could be as follows:

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

I hope I have been helpful.


#3

I tried that code but it returned with None rather than 40 (for 1 day)


#4

It is true, when verifying the function with values ​​smaller than 3, the condition escapes the sentence and does not return any value.

You could try with the code that explains the next level, that seems to be the right one:

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

#5

hi i was stuck at this level too just now and i tried everything to clear the level almost got pissed :smiley:
btw i got it and uhh heres my code hope it helps. im still very new tho

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

ps. i dont how but i tried to add on the 3 day discount that it has to be less than 7days.


#7

Thanks for you help :slight_smile:


#8

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