Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid setting encapsulation challenge too early #579

Merged
merged 1 commit into from
Dec 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions _episodes/16-writing-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,7 @@ result of call is: None
> ## Encapsulation of an If/Print Block
>
> The code below will run on a label-printer for chicken eggs. A digital scale will report a chicken egg mass (in grams)
> to the computer and then the computer will print a label.
>
> Please re-write the code so that the if-block is folded into a function.
> to the computer and then the computer will print a label.
>
> ~~~
> import random
Expand All @@ -374,7 +372,9 @@ result of call is: None
> {: .language-python}
>
>
> The simplified program follows. What function definition will make it functional?
> The if-block that classifies the eggs might be useful in other situations,
> so to avoid repeating it, we could fold it into a function, `get_egg_label()`.
> Revising the program to use the function would give us this:
>
> ~~~
> # revised version
Expand All @@ -385,7 +385,7 @@ result of call is: None
> # the (random) mass will be 70 +/- 20 grams
> mass = 70 + 20.0 * (2.0 * random.random() - 1.0)
>
> print(mass, get_egg_label(mass))
> print(mass, get_egg_label(mass))
>
> ~~~
> {: .language-python}
Expand Down