7. plan your Trip


#1

hi, how can i make this code run?
it give me error that global var Nights is not defined. i guess the code itself is functional but do not know how to cvall it in right way. thanks in advance

def hotel_cost():
    nights = input("how many days?")
    return 140 * nights

def plane_ride_cost():
    city = str(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
    else:
        
def rental_car_cost():
    days = 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 trip_cost(city,days):
    return nights + city + pro_day + spending_money
    
print trip_cost(hotel_cost(),plane_ride_cost(),rental_car_cost()+ spending_money)

ok after help from some coders from WWW i managed it to work, you can check it to understand how it works , for me it is usefull to understand "how rabbit runs".

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

#2

Hi here the instruction..

1 Below your existing code, define a function called trip_cost that takes two arguments, city and days.

def trip_cost(city,days):

2 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.

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

#3

thanks but i already passed challenge as it was in left side with instructions. but what i wrote it is modification with inputs. i want to give user (me) chance to choose from console what city , days.


#4

def trip_cost(city, days,):
return plane_ride_cost(city) + rental_car_cost(days) + days * 140

It's right like this