Inconsistency in instructions


#1


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


In step 2 of the exercise, the instructions say to assign the argument 'nights' to the function 'hotel_cost', whereas in step 5 of the exercise, it says to call hotel_cost(days) not hotel_cost(nights). Because the function car_rental_cost also takes the argument 'days', the trip_cost function is returning a value using the definition of days as given when calculating car_rental_cost which differs from the number of nights.

Using the responses 4 (nights in the hotel), 4 (destination of LA), and 5 (number of days for the rental car), the answer should be 1185 and not 1325. But because the exercise rejects the trip_cost function if you list more than 2 arguments, it forces you to use 'days' for both hotel_cost and rental_car_cost, contradictory to the instructions in step 2.


days = raw_input("How many nights will you be staying?")

def hotel_cost(days):
    return 140 * int(days)
    print hotel_cost
    
destinations = ["Charlotte", "Tampa", "Pittsburgh", "Los Angeles"]

city = destinations[int(raw_input("Enter the number corresponding to your destination: \n1 - %s \n2 - %s \n3 - %s \n4 - %s\n" % (destinations[0], destinations[1], destinations[2], destinations[3]))) - 1]

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

days = raw_input("For how many days will you rent a car?")

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

def trip_cost(city, days):
    return hotel_cost(days) + plane_ride_cost(city) + rental_car_cost(days)
    
print hotel_cost(days)
print plane_ride_cost(city)
print rental_car_cost(days)
print trip_cost(city, days)

It should allow me to pass this step using the code below, which returns the correct answer:

nights = raw_input("How many nights will you be staying?")

def hotel_cost(nights):
    return 140 * int(nights)
    print hotel_cost
    
destinations = ["Charlotte", "Tampa", "Pittsburgh", "Los Angeles"]

city = destinations[int(raw_input("Enter the number corresponding to your destination: \n1 - %s \n2 - %s \n3 - %s \n4 - %s\n" % (destinations[0], destinations[1], destinations[2], destinations[3]))) - 1]

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

days = raw_input("For how many days will you rent a car?")

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

def trip_cost(nights, city, days):
    return hotel_cost(nights) + plane_ride_cost(city) + rental_car_cost(days)
    
print hotel_cost(nights)
print plane_ride_cost(city)
print rental_car_cost(days)
print trip_cost(nights, city, days)

#2

its not inconsistent, the problem is that you include everything in a exercise (then the exercise becomes massive)

like, what is if the user enters invalid input? How can you keep prompting the user for valid input? And so on.


#3

While the code is valid (purely in terms of syntax) and does run with python trip_cost(city, days) , it does not return a value that is the actual cost of the trip. In other words, you are allowed to reassign arguments to different functions, but for this problem it does not lead to the correct answer. The code that the module requires me to type in order to pass results in the first 3 values printed at the end not adding up to the printed trip_cost. The way the module allows you to move to the next step gives the answer 1325 (wrong) and not 1185 (correct).


#4

But inside codecademy you are bound to what the exercise is telling you, you have the freedom to expand the programs you write outside the courses, i would encourage you to do so


#5

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