What is wrong with my code ?!


#1



def hotel_cost(nights):
    return 140 * nights
    
def plane_ride_cost(city):
    if city=="Charlotte":
        return 183
    elif city=="Tampa":
        return 220
    elif city=="Pittsburgh":
        return 222
    elif city=="Los Angeles":
        return 475   
        
def rental_car_cost(days):
    if days>=7:
        return days*40-50
    elif (days >=3) and (days<7) :
        return days*40-20
    else :
        return days*40
        
    def trip_cost(c, d):
        return rental_car_cost(d) + hotel_cost(d) + plane_ride_cost(c)


#2

Looks like it is inside the rental_car_cost code block. Needs to be against left margin.

The variable names may be okay, the exercise expects days and city.

Aside

The upper bound has already been tested. No need for and days < 7. There is repetition in the code that can be simplified...

cost = days * 40

Now just test the >= 7 and >= 3 cases and apply the discount to cost.

cost -= 60

We don't need an else branch.

if ___:

elif ___:

return cost

#3

hhhhhhhhhhhhh the problem was that there is a space before Def trip_cost(c,d)
:joy:
thank you for your help :* :* :*


#4

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