Transportation 4/7 Correct Example – Codeacademy

Here is a correct example for the “Transportation” exercise from the Python course from Codeacademy:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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):
    cost = 40 * days
    if days >= 7:
        cost = 40 * days - 50
    elif days >= 3:
        cost = 40 * days - 20
    return cost

Instruction: “if you rent the car for 7 or more days, you get $50 off your total.”
So the line should be cost = 40(dollars) * days(input) – 50(dollars).

codeacademy

3 COMMENTS

  • tim says:18.07.2015

    This isn’t working in codecademy!!! there is an error that needs to be fixed!

  • tim says:18.07.2015

    the error isn’t in the code its in the website.

  • Armand says:12.09.2016

    There is no error on the website, the instructions are just a little vague.

    TIP: remember to define that the day range for the middle step (days * 40 – 20) is BOTH greater than or equal to 3 days AND less than 7 days.
    Also, the instructions neglect to mention that you need to define a base cost for less than 3 days, which will have the default cost of days*40.

    SPOILER!!!
    The following code is correct:

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

ADD A COMMENT: