Python 8:5


#1

So i think i have everything correct by im not sure it keeps popping up errors:
def hotel_cost(nights):

return 140 * nights

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):

rentalcarcost = 40 * days 

if days >= 7:
   return rentalcarcost - 50

elif days >= 3: 
      return rentalcarcost -20

else:      
      return rentalcarcost

def trip_cost(city, days):

trip_cost = rental_car_cost(days) + hotel_cost(nights) + plane_ride_cost(city)

and here is the error:
Oops, try again. trip_cost('Charlotte', 0) raised an error: global name 'nights' is not defined


#2

The argument in the trip_cost() function is called 'days', not 'nights'! Either you have to pass the same value (days) into the hotel_cost() function, or you have to convert days into nights. Most of the time, you need a hotel for one night less than the total number of days you are staying...

Hope that helps

Tim F


#3

Thanks Im so dumb for not seeing that before


#4

Not dumb at all :wink:

Just a question of stepping back and not getting bogged down in the detail.

Good luck!

Tim F


#5

Hey so on the next one it tells me to do this:

Modify your trip_cost function definition. Add a third argument, spending_money.
Modify what the trip_cost function does. Add the variable spending_money to the sum that it returns.
so i did this:
def trip_cost(city, days, spending_money):

return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city)
return sum(total_cost)+ spending_money

now i get errors


#6

You just need one return statement. Just add spending_money to the first one. No need for the second return.


#7

Thanks for the help. It Worked


#8

Hi its me again i've done everything right but it wont print:

def hotel_cost(nights):
return 140 * nights
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):

rentalcarcost = 40 * days 

if days >= 7:
   return rentalcarcost - 50

elif days >= 3: 
      return rentalcarcost -20

else:      
      return rentalcarcost

def trip_cost(city, days, spending_money):

return rental_car_cost(days) + hotel_cost(days) + plane_ride_cost(city) + spending_money
print trip_cost("Los Angeles", 5 , 600)

please help


#9

Unindent your last print statement.

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

print trip_cost("Los Angeles", 5 , 600)

Should look like this.


#10

thanks that helped. ive got another problem now


#11

this is my code and ive got it all right but it gives me an error:

suitcase = []
suitcase.append("sunglasses")

Your code here!

suitcase.append('bathing suit')
suitcase.append('wallet')
suitcase.append('extra clothes')

list_length = 4 # Set this to the length of suitcase

print "There are %d items in the suitcase." % (list_length)
print suitcase

if you could please help me out


#12

I believe they want you to use the len() instead of simply putting 4.


#13

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