7 Taking a vacation


#1

I need help with 7 plan your trip
I don't know what is wrong with my code:
def hotel_cost():
nights = int(raw_input("how many days?"))
return 140 * nights

def plane_ride_cost():
city = raw_input("which city? Charlotte, Tampa, Pittsburgh or Los Angeles?")
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 = int(raw_input("how many days for renting a car?"))
pro_day = days * 40
if days >= 7:
return pro_day - 50
elif days >=3:
return pro_day - 20
else:
return pro_day

def spending_money():
money_spent = int(raw_input("how much money will you spend there?"))
return money_spent

def trip_cost():
return hotel_cost() + plane_ride_cost() + rental_car_cost() + spending_money()

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

here is the error:

Traceback (most recent call last):
File "python", line 35, in
TypeError: trip_cost() takes no arguments (3 given)


#2

So,

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

#3

Guys!
Really!
What's wrong with it? I can't understand

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):
    cost = 40 * days
    if days >= 7:
        cost -= 50
    elif days >= 3:
        cost -= 20
    return cost
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)

#4

Hi what error do you get?


#5

This line should be outside of the function block, in global scope. Remove the indentation.


#6

you need to define spending money
def spending_money(spending_money):
return spending_money


#7

It is defined in the trip_cost function as a parameter.


#8

So, error is: «Oops, try again. It looks like nothing was printed to the console!»


#9

Why it should be in a global scope? And why the other elif shouldn't be in a global scope as well? :slight_smile:


#11

HI this line

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

Shoudn't be indent


#12

Yeah, I've already done it in the right way) and it works!
Thank you @mtf


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

#17

Thats the coding im using for the function rental_car_cost, however i cant get it to work. Suggestions appreciated. Thanks.


#18

so would you put the print in the function?


#19

No. It should be outside of, and print the return value of the function.


#20

thank you for answering my question.