Taking a Vacation


#1

I am having troubles with my code can someone please tell me what am I doing wrong

def hotel_cost(nigths):
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 = days*40
if days >= 7:
cost = cost -50
return cost
elif days < 7 and days >= 3:
return cost - 20
else:
return cost;

def trip_cost(nigths, city, days)
return (hotel_cost(nights) + plane_ride_ticket(city) + rental_car_cost(days))

Oops, try again. Your code looks a bit off. Feel free to peek back at earlier exercises if you need a refresher! Take a look at the console window for the error message from the interpreter.

Thank you for your support!


#2

Ok so,

1.You are missing a : after you declared your function:

def trip_cost(nigths, city, days)

2.Make sure you spell "nights" correctly or else it's going to throw a global variable error.
3.In the instructions, it clearly states that trip_cost (your last function) takes in two parameters (city and days).
4.Since that function takes in only city and days, change you parameter in hotel_cost(nights) to days => hotel_cost(days) or else it's going to throw a global variable error:

def trip_cost(nigths, city, days)
    return (hotel_cost(nights) + plane_ride_ticket(city) + rental_car_cost(days))

5.You don't have a function called plane_ride_ticket. Are you referring to your plane_ride_cost function?
6.Make sure you indent properly!


#3

You are absolutely right thank you very much!!
this was of great help


#4

Hi,

Could you help me with the following? It throws an error like, 'Oops, try again. trip_cost should take exactly 3 arguments!'

def plane_ride_cost(city):
if city=="Charlotte":
return 183
elif city=="Tampa":
return 220
elif city=="Pittsburgh":
return 222
else:
return 475

def hotel_cost(days):
return 140*days

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

def spending_money(days):
return 200*days
#expense

def trip_cost(city,days):
return plane_ride_cost(city)+rental_car_cost(days)+spending_money(days)+hotel_cost(days)
print trip_cost("Tampa",3)

Thanks in advance for your help.


#5

def trip_cost(city,days):
return plane_ride_cost(city)+rental_car_cost(days)+spending_money(days)+hotel_cost(days)
print trip_cost("Tampa",3)

You also need to take some money to spend.
After "days" in the brackets there should be something else.


#6

Thanks for you response. However could you clarify what you meant by "You also need to take some money to spend." spending_money already have an argument called days. It am taking 200 per day. That's why I return 200*days.
Also I do not thing there should be anything else after days in def trip_cost(city,days) because there are no other argument of assign here. Or I am missing something glaring! Thanks for you help.


#7

I do not like telling people, but oh well.

After days you need to add an argument called "spending_money"


#8

I don't think so spending_money is not an argument it is a definition. What goes in the bracket is an argument. The argument of spending_money is days. This correspond to the argument for trip_cost, When I run my code using TextWrangler it runs fine and gives me correct solution. Only it happen in the code academy editor.


#9

I'm just saying what I did and what worked for me


#10

I don't know where you got the

def spending_money(days):
    return 200*days
#expense

from since it's not in any of the instructions (people need to be able to enter ANY amount of spending money (not just multiple of 200$).
Just simply remove that and add spending_money to trip_cost's parameter and equation:

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

People just enter a spending money amount and it just adds to the trip_cost. It is an argument. Please read the instructions carefully (referring to lesson 6 instruction 1).


#11

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