Loading…
None
String updated in the repository |
|
None
String updated in the repository |
|
echar
Translation changed |
|
None
String updated in the repository |
|
echar
Translation changed |
|
echar
Translation changed |
|
NagaYZ
Marked for edit |
|
addon:prefill
Automatically translated |
|
None
String updated in the repository |
|
Things to check
Key
adventures->functions->levels->12->story_textFlags
ignore-double-space, ignore-ellipsis, ignore-inconsistent, ignore-long-untranslated, ignore-same, ignore-translated, placeholders:r"`([^`\n\r]+)`|## ", python-brace-format
To create a function, use `{define}` and give the function a name. Then put all the lines you want in the function in a indented block under the `{define}` line.
Leave one empty line in your code to make it look nice and neat. Great job! You have created a function!
Now, whenever we need that block of code, we just use <code>{call}</code> with the function's name to call it up! We don't have to type that block of code again.
Check out this example code of a game of Twister. The function 'turn' contains a block of code that chooses which limb should go where.
### Exercise
Finish this code by setting the 2 variables chosen_limb and chosen_color.
Then, choose how many times you want to call the function to give the twister spinner a spin.
### Exercise 2
Improve your code by adding a variable called 'people'. Use the variable to give all the players their own command in the game.
For example: 'Ahmed, right hand on green' or 'Jessica, left foot on yellow'.
Pour créer une fonction, utilise `{define}` et donne un nom à la fonction. Ensuite, ajoute toutes les lignes que tu veux dans la fonction dans un bloc indenté, sous la ligne du `{define}`.
Laisse une ligne vide après le bloc pour rendre ton code beau et propre. Bon travail ! tu as créé une fonction !
Maintenant, quand nous aurons besoin de ce bloc de code, nous pourrons juste appeler la fonction avec `{call}` suivi du nom de la fonction ! Nous n'aurons plus besoins d'écrire ce bloc
aà nouveau.Regarde cet exemple de code du jeu Twister. La fonction « joue_un_tour » contient un bloc de code qui choisi quel membre doit aller où.
### Exercice
Termine ce code en complétant les lignes des deux variables `membre_choisi` et `couleur_choisi`.
Ensuite, choisi combien de fois tu veux appeler la fonction pour faire des tours de Twister.
### Exercice 2
Améliore ton code en ajoutant une variable « personnes ». Utilise la variable pour distribuer aux joueurs et joueuses leur instruction de jeu personnelle.
Par exemple : « Ahmed, main droit
`{define}`e sur vert » ou « Jessica, pied gauche sur jaune ».