Thursday, June 6, 2013

Python : Taking a Vacation



def hotel_cost(nights):
    return nights * 140

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

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)

# return trip

def hotel_cost(nights):
    return nights * 140

bill = hotel_cost(5)

def add_monthly_interest(balance):
    return balance * (1 + (0.15 / 12))

def make_payment(payment, balance):
    new_balance = add_monthly_interest(balance - payment)

    return "You still owe: " + str(new_balance)
 
hotel_cost(5)  
print make_payment(100, hotel_cost(5) )

1 comment: