Help understanding functions. Code not working, Vacation Altogether Now with inputs


Hi there,

I am still trying to wrap my head around functions. I am trying to include get my code to accept input to use in functions and then print the total cost

def hotel_cost(n):
    return 140 * n

def plane_ride_cost(city):
    if city.lower() == "charlotte":
        return 183
    elif city.lower() == "tampa":
        return 220
    elif city.lower() == "pittsburgh":
        return 222
    elif city.lower() == "los angeles":
        return 475

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

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

hotel = int(raw_input("How many nights in the hotel? "))
plane = raw_input('Charlotte, Tampa, Pittsburgh or Los Angeles? ')
rental = int(raw_input("How many days driving? "))
spending_money = int(raw_input("How much spending money? "))
print trip_cost(rental_car_cost(rental) + hotel_cost(hotel) + plane_ride_cost(plane) + spending_money)

the error i get is:

Traceback (most recent call last):
File "C:/Users/Celeste/PycharmProjects/Codeacademy 5 Vacation/5.", line 31, in
print trip_cost(rental_car_cost(rental) + hotel_cost(hotel) + plane_ride_cost(plane) + spending_money)
TypeError: trip_cost() takes exactly 4 arguments (1 given)

Process finished with exit code 1

Any advice would be greatly appreciated, I am very new to coding and python and have never posted on a forum before but I am so confused at the moment


From what I can see, everything looks okay except for your trip_cost function. The parameters of a function (things that are in parenthesis) are like variables that can be used in the function and are assigned a value of whatever you pass to them. The issue with your code is that your parameters are city, days, nights, money. This is fine, but you use spending_money as a variable within the function, which is not defined anywhere. Try changing the money variable to spending_money and it should work a lot better.


what is wrong in my code...

def rental_car_cost(days):
return 140*night
def plane_ride_cost(city):
if input(city) =='Charlotte':
return "183"
elif input(city)=='Tampa':
return "220"
elif input(city) =='Pittsburgh':
return "222"
return "475"

def rental_car_cost(days):
total = 40 * days
if days >= 7:
total -= 50
elif days >=3:
total -= 20
return total
def trip_cost(city, days, nights):
return plane_ride_cost(city) + rental_car_cost(days) + hotel_cost(nights)