Skip to content

Commit 8fc254b

Browse files
committed
Episode 06: fix python code blocks
1 parent cd49c16 commit 8fc254b

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

_episodes/06-loops-and-functions.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ these files using the module `os`:
9696

9797
The command `os.mkdir` is equivalent to `mkdir` in the shell. Just so we are
9898
sure, we can check that the new directory was created within the `data` folder:
99-
10099
~~~
101-
>>> os.listdir('data')
100+
os.listdir('data')
101+
~~~
102+
{: .language-python}
103+
~~~
102104
['plots.csv',
103105
'portal_mammals.sqlite',
104106
'species.csv',
@@ -108,7 +110,7 @@ sure, we can check that the new directory was created within the `data` folder:
108110
'surveys2002_temp.csv',
109111
'yearly_files']
110112
~~~
111-
{: .language-python}
113+
{: .output}
112114

113115
The command `os.listdir` is equivalent to `ls` in the shell.
114116

@@ -146,8 +148,10 @@ We have seen that we can loop over a list of items, so we need a list of years
146148
to loop over. We can get the years in our DataFrame with:
147149

148150
~~~
149-
>>> surveys_df['year']
150-
151+
surveys_df['year']
152+
~~~
153+
{: .language-python}
154+
~~~
151155
0 1977
152156
1 1977
153157
2 1977
@@ -158,7 +162,7 @@ to loop over. We can get the years in our DataFrame with:
158162
35547 2002
159163
35548 2002
160164
~~~
161-
{: .language-python}
165+
{: .output}
162166

163167
but we want only unique years, which we can get using the `unique` method
164168
which we have already seen.
@@ -464,10 +468,11 @@ argument with default values (which are optional in the function call).
464468
~~~
465469
{: .language-python}
466470

467-
```
471+
~~~
468472
Both optional arguments: 1988 1993
469473
Default values: 1977 2002
470-
```
474+
~~~
475+
>> {: .output}
471476
472477
The "\t" in the `print` statements are tabs, used to make the text align and be
473478
easier to read.
@@ -501,10 +506,11 @@ dates are not provided:
501506
print('Default values:\t\t\t', start, end)
502507
~~~
503508
{: .language-python}
504-
```
509+
~~~
505510
Both optional arguments: 1988 1993
506511
Default values: 1977 2002
507-
```
512+
~~~
513+
>> {: .output}
508514
509515
The default values of the `start_year` and `end_year` arguments in the function
510516
`yearly_data_arg_test` are now `None`. This is a build-it constant in Python
@@ -555,9 +561,10 @@ of code when some condition is met. They commonly look something like this:
555561

556562
Which would return:
557563

558-
```
564+
~~~
559565
a is a positive number
560-
```
566+
~~~
567+
>> {: .output}
561568
562569
Change the value of `a` to see how this function works. The statement `elif`
563570
means "else if", and all of the conditional statements must end in a colon.
@@ -600,14 +607,15 @@ values to the function using these keywords:
600607
print('One keyword, default start:\t', start, end)
601608
~~~
602609
{: .language-python}
603-
```
610+
~~~
604611
Default values: 1977 2002
605612
No keywords: 1988 1993
606613
Both keywords, in order: 1988 1993
607614
Both keywords, flipped: 1988 1993
608615
One keyword, default end: 1988 2002
609616
One keyword, default start: 1977 1993
610-
```
617+
~~~
618+
>> {: .output}
611619
612620
> ## Challenge - Modifying functions
613621
>

0 commit comments

Comments
 (0)