Taking a vacation



Oops, try again. trip_cost('Los Angeles', 3) raised an error: global name 'nights' is not defined

The program encounters an error, which is weird. Also, I didn't really understand the example. It was:

def double(n):
return 2 * n
def triple(p):
return 3 * p

def add(a, b):
return double(a) + triple(b)`

I understand double and triple, but what do a and b have to do with anything?

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



The second instruction says:

02 Like the example above, have your function return the sum of calling the rental_car_cost(days), hotel_cost(days), and plane_ride_cost(city) functions.

So, this line:

should have its hotel_cost parameter as days and not nights.

I hope this helps! :slight_smile: :wink:


Ok, I thought I'd figured this out, but I havent.
start_list = [5, 3, 1, 2, 4]
square_list = []

Your code here!

for list in start_list:
start_list.append(list ** 2)

print square_list

That's my code. The site kept on saying the code took too long to process and to check for infinite loops. I thought it was a bug and ran it in PyDev, but it also didn't render. It took about 2 minutes for it to process, and then nothing appeared on the screen. It's just that python program, not others. Please help!


Well, you should have started this as a new topic, but here:

you need to append to square_list and not what you have. That is where your output goes. Remember, you set it as an empty array.


and it should now print out:

[1, 4, 9, 16, 25]


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