Skip to content

Commit

Permalink
📜 Explain functions and in range in level 18 (#5471)
Browse files Browse the repository at this point in the history
Fixes #5224 

The syntax of functions and in range in level 18 is now explained.
  • Loading branch information
MarleenGilsing authored Apr 26, 2024
1 parent 202a683 commit 24e1d50
Show file tree
Hide file tree
Showing 52 changed files with 1,891 additions and 1 deletion.
37 changes: 37 additions & 0 deletions content/adventures/ar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,14 @@ adventures:
{print} i
{print} 'Ready or not, here I come!'
```
18:
story_text: |
Lastly, we'll turn `{for} i {in} {range} 1 to 5` into real Python code, like this:
example_code: |
```
{for} i {in} {range}(1,5):
{print} (i)
```
fortune:
name: العراف
default_save_name: العراف
Expand Down Expand Up @@ -1903,6 +1911,35 @@ adventures:
new_price = _ calculate_new_price {with} old_price, _
{print} 'The new price is ' new_price ' dollar'
```
18:
story_text: |
Let's make functions the Pythons way! To define a function, we no longer use:
`{define} name_function {with} argument_1, argument_2:`
but we use:
`{def} name_function(argument_1, argument_2):`.
If you don't want to use arguments, you just leave the space between the parantheses empty.
To call a function, we don't need the `{call}` command anymore. You just type the name of the function.
example_code: |
```
{def} calculate_score(answer, correct_answer):
{if} answer == correct_answer:
score = 1
{elif} answer == '?':
score = 0
{else}:
score = -1
{return} score
answer = {input} ('Where can you find the Eiffel Tower?')
correct_answer = 'Paris'
score = calculate_score(answer, correct_answer)
{print} ('Your score is... ', score)
```
guess_my_number:
name: Guess my number
default_save_name: guess my number
Expand Down
37 changes: 37 additions & 0 deletions content/adventures/bg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,14 @@ adventures:
{print} i
{print} 'Ready or not, here I come!'
```
18:
story_text: |
Lastly, we'll turn `{for} i {in} {range} 1 to 5` into real Python code, like this:
example_code: |
```
{for} i {in} {range}(1,5):
{print} (i)
```
fortune:
name: Fortune teller
default_save_name: Fortune Teller
Expand Down Expand Up @@ -2044,6 +2052,35 @@ adventures:
new_price = _ calculate_new_price {with} old_price, _
{print} 'The new price is ' new_price ' dollar'
```
18:
story_text: |
Let's make functions the Pythons way! To define a function, we no longer use:
`{define} name_function {with} argument_1, argument_2:`
but we use:
`{def} name_function(argument_1, argument_2):`.
If you don't want to use arguments, you just leave the space between the parantheses empty.
To call a function, we don't need the `{call}` command anymore. You just type the name of the function.
example_code: |
```
{def} calculate_score(answer, correct_answer):
{if} answer == correct_answer:
score = 1
{elif} answer == '?':
score = 0
{else}:
score = -1
{return} score
answer = {input} ('Where can you find the Eiffel Tower?')
correct_answer = 'Paris'
score = calculate_score(answer, correct_answer)
{print} ('Your score is... ', score)
```
guess_my_number:
name: Guess my number
default_save_name: guess my number
Expand Down
37 changes: 37 additions & 0 deletions content/adventures/bn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,14 @@ adventures:
{print} i
{print} 'Ready or not, here I come!'
```
18:
story_text: |
Lastly, we'll turn `{for} i {in} {range} 1 to 5` into real Python code, like this:
example_code: |
```
{for} i {in} {range}(1,5):
{print} (i)
```
fortune:
name: Fortune teller
default_save_name: Fortune Teller
Expand Down Expand Up @@ -1955,6 +1963,35 @@ adventures:
new_price = _ calculate_new_price {with} old_price, _
{print} 'The new price is ' new_price ' dollar'
```
18:
story_text: |
Let's make functions the Pythons way! To define a function, we no longer use:
`{define} name_function {with} argument_1, argument_2:`
but we use:
`{def} name_function(argument_1, argument_2):`.
If you don't want to use arguments, you just leave the space between the parantheses empty.
To call a function, we don't need the `{call}` command anymore. You just type the name of the function.
example_code: |
```
{def} calculate_score(answer, correct_answer):
{if} answer == correct_answer:
score = 1
{elif} answer == '?':
score = 0
{else}:
score = -1
{return} score
answer = {input} ('Where can you find the Eiffel Tower?')
correct_answer = 'Paris'
score = calculate_score(answer, correct_answer)
{print} ('Your score is... ', score)
```
guess_my_number:
name: Guess my number
default_save_name: guess my number
Expand Down
37 changes: 37 additions & 0 deletions content/adventures/ca.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,14 @@ adventures:
{print} i
{print} 'Ready or not, here I come!'
```
18:
story_text: |
Lastly, we'll turn `{for} i {in} {range} 1 to 5` into real Python code, like this:
example_code: |
```
{for} i {in} {range}(1,5):
{print} (i)
```
fortune:
name: Fortune teller
default_save_name: Fortune Teller
Expand Down Expand Up @@ -2031,6 +2039,35 @@ adventures:
new_price = _ calculate_new_price {with} old_price, _
{print} 'The new price is ' new_price ' dollar'
```
18:
story_text: |
Let's make functions the Pythons way! To define a function, we no longer use:
`{define} name_function {with} argument_1, argument_2:`
but we use:
`{def} name_function(argument_1, argument_2):`.
If you don't want to use arguments, you just leave the space between the parantheses empty.
To call a function, we don't need the `{call}` command anymore. You just type the name of the function.
example_code: |
```
{def} calculate_score(answer, correct_answer):
{if} answer == correct_answer:
score = 1
{elif} answer == '?':
score = 0
{else}:
score = -1
{return} score
answer = {input} ('Where can you find the Eiffel Tower?')
correct_answer = 'Paris'
score = calculate_score(answer, correct_answer)
{print} ('Your score is... ', score)
```
guess_my_number:
name: Guess my number
default_save_name: guess my number
Expand Down
37 changes: 37 additions & 0 deletions content/adventures/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,14 @@ adventures:
{print} i
{print} 'Ready or not, here I come!'
```
18:
story_text: |
Lastly, we'll turn `{for} i {in} {range} 1 to 5` into real Python code, like this:
example_code: |
```
{for} i {in} {range}(1,5):
{print} (i)
```
fortune:
name: Fortune teller
default_save_name: Fortune Teller
Expand Down Expand Up @@ -2007,6 +2015,35 @@ adventures:
new_price = _ calculate_new_price {with} old_price, _
{print} 'The new price is ' new_price ' dollar'
```
18:
story_text: |
Let's make functions the Pythons way! To define a function, we no longer use:
`{define} name_function {with} argument_1, argument_2:`
but we use:
`{def} name_function(argument_1, argument_2):`.
If you don't want to use arguments, you just leave the space between the parantheses empty.
To call a function, we don't need the `{call}` command anymore. You just type the name of the function.
example_code: |
```
{def} calculate_score(answer, correct_answer):
{if} answer == correct_answer:
score = 1
{elif} answer == '?':
score = 0
{else}:
score = -1
{return} score
answer = {input} ('Where can you find the Eiffel Tower?')
correct_answer = 'Paris'
score = calculate_score(answer, correct_answer)
{print} ('Your score is... ', score)
```
guess_my_number:
name: Guess my number
default_save_name: guess my number
Expand Down
37 changes: 37 additions & 0 deletions content/adventures/cy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1767,6 +1767,14 @@ adventures:
{print} i
{print} 'Ready or not, here I come!'
```
18:
story_text: |
Lastly, we'll turn `{for} i {in} {range} 1 to 5` into real Python code, like this:
example_code: |
```
{for} i {in} {range}(1,5):
{print} (i)
```
fortune:
name: Fortune teller
default_save_name: Fortune Teller
Expand Down Expand Up @@ -2025,6 +2033,35 @@ adventures:
new_price = _ calculate_new_price {with} old_price, _
{print} 'The new price is ' new_price ' dollar'
```
18:
story_text: |
Let's make functions the Pythons way! To define a function, we no longer use:
`{define} name_function {with} argument_1, argument_2:`
but we use:
`{def} name_function(argument_1, argument_2):`.
If you don't want to use arguments, you just leave the space between the parantheses empty.
To call a function, we don't need the `{call}` command anymore. You just type the name of the function.
example_code: |
```
{def} calculate_score(answer, correct_answer):
{if} answer == correct_answer:
score = 1
{elif} answer == '?':
score = 0
{else}:
score = -1
{return} score
answer = {input} ('Where can you find the Eiffel Tower?')
correct_answer = 'Paris'
score = calculate_score(answer, correct_answer)
{print} ('Your score is... ', score)
```
guess_my_number:
name: Guess my number
default_save_name: guess my number
Expand Down
37 changes: 37 additions & 0 deletions content/adventures/da.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,14 @@ adventures:
{print} i
{print} 'Ready or not, here I come!'
```
18:
story_text: |
Lastly, we'll turn `{for} i {in} {range} 1 to 5` into real Python code, like this:
example_code: |
```
{for} i {in} {range}(1,5):
{print} (i)
```
fortune:
name: Fortune teller
default_save_name: Fortune Teller
Expand Down Expand Up @@ -2007,6 +2015,35 @@ adventures:
new_price = _ calculate_new_price {with} old_price, _
{print} 'The new price is ' new_price ' dollar'
```
18:
story_text: |
Let's make functions the Pythons way! To define a function, we no longer use:
`{define} name_function {with} argument_1, argument_2:`
but we use:
`{def} name_function(argument_1, argument_2):`.
If you don't want to use arguments, you just leave the space between the parantheses empty.
To call a function, we don't need the `{call}` command anymore. You just type the name of the function.
example_code: |
```
{def} calculate_score(answer, correct_answer):
{if} answer == correct_answer:
score = 1
{elif} answer == '?':
score = 0
{else}:
score = -1
{return} score
answer = {input} ('Where can you find the Eiffel Tower?')
correct_answer = 'Paris'
score = calculate_score(answer, correct_answer)
{print} ('Your score is... ', score)
```
guess_my_number:
name: Guess my number
default_save_name: guess my number
Expand Down
Loading

0 comments on commit 24e1d50

Please sign in to comment.