Skip to content

Commit 02c6296

Browse files
committed
changed to a travel theme
1 parent ee58bf6 commit 02c6296

File tree

2 files changed

+105
-122
lines changed

2 files changed

+105
-122
lines changed

README.md

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11

22
# Functions lab
33

4-
As we know, we can use functions to give a name to sequences of our code, to make it more expressive. We can also use functions to allow us to reuse code. In this lab we will get practice in using functions for these purposes.
4+
## Introduction
55

6-
### Objectives
6+
As we know, we can use functions to name sequences of our code, thus making our code more expressive. We can also use functions to allow us to reuse our code. In this lab we will practice using functions for these purposes.
77

8-
* Practice declaring and returning values from function
9-
* Practice accessing variables outside of a function's scope, from inside of a function
8+
## Objectives
109

11-
### Writing our first functions
10+
* Practice declaring and returning values from functions
11+
* Practice accessing variables that are outside of a function's scope, from inside of a function
1212

13-
Imagine we work in a diner. We have a list of `orders` which we assign below. Write a function called `number_of_orders` that returns the current number of orders.
13+
## Writing our first functions
14+
15+
Imagine we are working on our list of travel destinations -- which is really turning out to be a full time job. We have our list of `travel_destinations` which we assign below. Write a function called `number_of_destinations` that returns the number of destinations we have on our list.
1416

1517

1618
```python
17-
orders = ['turkey sandwich', 'eggs']
18-
def number_of_orders():
19+
travel_destinations = ['argentina', 'mexico', 'italy']
20+
def number_of_destinations():
1921
pass
2022
```
2123

2224

2325
```python
24-
number_of_orders() # 2
26+
number_of_destinations() # 3
2527
```
2628

27-
Now write another function called `next_up` that returns the first order (the order with the lowest index), in the `orders` list.
29+
Now write another function called `next_up` that returns our first destination (the destination with the lowest index), in the `travel_destinations` list.
2830

2931

3032
```python
@@ -34,66 +36,62 @@ def next_up():
3436

3537

3638
```python
37-
orders = ['turkey sandwich', 'eggs']
38-
next_up() # 'turkey sandwich'
39+
travel_destinations = ['argentina', 'mexico', 'italy']
40+
next_up() # 'argentina'
41+
```
42+
3943

40-
orders = ['beet salad', 'fennel']
41-
next_up() # 'beet salad'
44+
```python
45+
travel_destinations = ['finland', 'canada', 'croatia']
46+
next_up() # 'finland'
4247
```
4348

44-
Ok, now write a function called `healthy_order` that returns the string `'spinach salad'`.
49+
Ok, now write a function called `favorite_destination` that returns the string `'madagascar'`.
4550

4651

4752
```python
48-
def healthy_order():
53+
def favorite_destination():
4954
pass
5055
```
5156

5257

5358
```python
54-
healthy_order() # 'spinach salad'
59+
favorite_destination() # 'madagascar'
5560
```
5661

57-
Now let's declare an array called `orders`. Change the function `healthy_order` so that it continues to return the string `'spinach salad'`, but also adds the string `'spinach salad'` to the end of the list of orders.
62+
Again, let's declare an array called `travel_destinations`. Change the function `favorite_destination` so that it continues to return the string `'madagascar'`, but also adds the string `'madagascar'` to the end of the list of destinations.
5863

5964

6065
```python
61-
orders = ['turkey sandwich', 'eggs']
62-
healthy_order()
63-
orders[-1] # 'spinach salad'
66+
travel_destinations = ['argentina', 'mexico', 'italy', 'finland', 'canada', 'croatia']
67+
favorite_destination()
68+
travel_destinations[-1] # 'madagascar'
6469
```
6570

66-
67-
68-
69-
'eggs'
70-
71-
72-
73-
Now let's write another function iterates through the list of `orders` and capitalizes the first letter of each word in the order. It should return a list of capitalized orders.
71+
Now let's write another function which iterates through the list of `destinations` and capitalizes the first letter of each word. It should return a list of capitalized destinations.
7472

7573

7674
```python
77-
orders = ['spinach salad', 'turkey sandwich']
78-
def capitalize_orders():
75+
travel_destinations = ['argentina', 'mexico', 'italy', 'finland', 'canada', 'croatia']
76+
def capitalize_countries():
7977
pass
8078
```
8179

8280

8381
```python
84-
capitalize_orders() # ['Spinach Salad', 'Turkey Sandwich']
82+
capitalize_countries() # ['Argentina', 'Mexico', 'Italy', 'Finland', 'Canada', 'Croatia']
8583
```
8684

87-
Now if someone adds, an upcapitalized order, we can simply call our function again to return a list of capitalized orders.
85+
Great! Now if someone adds a country that is lowercased to our list of destinations, we can simply call our function again to capitalize each of the destinations in the list.
8886

8987

9088
```python
91-
orders = ['spinach salad', 'turkey sandwich']
92-
capitalize_orders() # ['Spinach Salad', 'Turkey Sandwich']
93-
orders.append('eggs')
94-
capitalize_orders() # ['Spinach Salad', 'Turkey Sandwich', 'Eggs']
89+
travel_destinations = ['argentina', 'mexico', 'italy', 'finland', 'canada', 'croatia']
90+
capitalize_countries() # ['Argentina', 'Mexico', 'Italy', 'Finland', 'Canada', 'Croatia']
91+
travel_destinations.append('japan')
92+
capitalize_countries() # ['Argentina', 'Mexico', 'Italy', 'Finland', 'Canada', 'Croatia', 'Japan']
9593
```
9694

97-
### Summary
95+
## Summary
9896

99-
Great job. Through this lab you were able to get practice both writing and returning values from functions. You also practiced accessing variables not local to the function, but in the global scope.
97+
Great job! In this lab we were able to get practice both writing and returning values from functions. We also practiced accessing variables not local to the function but in the global scope.

0 commit comments

Comments
 (0)