Taking a vacation

Lesson 01/07 – Before We Begin

[code lang=”python”]
def answer ():
return 42
[/code]

Lesson 02/07 – Planning Your Trip

[code lang=”python”]
def hotel_cost (nights):
return 140 * nights
[/code]

Lesson 03/07 – Getting There

[code lang=”python”]
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
[/code]

Lesson 04/07 – Transportation

[code lang=”python”]
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):
if days < 3:
return 40 * days
elif days > 6:
return 40 * days – 50
else:
return 40 * days – 20
[/code]

Lesson 05/07 – Pull it Together

[code lang=”python”]
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):
if days < 3:
return 40 * days
elif days > 6:
return 40 * days – 50
else:
return 40 * days – 20
def trip_cost (city, days):
return rental_car_cost(days) + hotel_cost (days) + plane_ride_cost (city)
[/code]

Lesson 06/07 – Hey, You Never Know!

[code lang=”python”] def cube(n):
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):
if days < 3:
return 40 * days
elif days > 6:
return 40 * days – 50
else:
return 40 * days – 20
def trip_cost (city, days, spending_money):
return rental_car_cost(days) + hotel_cost (days) + plane_ride_cost (city) + spending_money
[/code]

Lesson 07/07 – Plan Your Trip!

[code lang=”python”]
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):
if days < 3:
return 40 * days
elif days > 6:
return 40 * days – 50
else:
return 40 * days – 20
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)
[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax