Help with Taking a Vacation


#1



https://www.codecademy.com/courses/python-beginner-P5YtY/1/3?curriculum_id=4f89dab3d788890003000096#

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

I wished for it to return an actual value.


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 40 * days - 50
    elif days >= 3:
        return 40 * days -20


#2

Your code for rental_car_cost(days) only work for day >=7 and >=3 as you wrote.
But the code want to test it for 1 day, so you didn't do any command for x days

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

What I did is just 40 * days at the first
for days >7 and >3 I just add discount


#3

I seem to be totally lost here is my code but it keeps returning that my calculation is off for 3 days or more
my code is below ,Have I missed something ?

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


#4

First error I see is you returning the cost too early

def rental_car_cost(days):
    cost = 40*days

Still no error here

return cost
Your costumer will complain, "I should get discount because I rent for 7days! why you don't count the discount first!

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

Because you already declared that cost = 40*days, you can shorten them by using cost = cost-50 or cost -= 50, I also don't see why you need to use ()

else: 
    return cost

You don't need this, in your code there are 3 commands
1. Normal cost
2. Discount
3. Discount 2
So you don't need the else because it's already covered in the first command/normal cost

That are some error I find, but I think the main reason of the error came from the return command


#5

Thanks that worked a charm


#6

Or

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


#7

What is wrong in the following? I get the following message: "It looks like rental_car_cost returns None instead of the correct amount (40) for 1 days."But i can't see where is the problem?

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