From eed434b4cdbb6b37bc62ffefb195731c08e31767 Mon Sep 17 00:00:00 2001 From: Konstantin Chaika <konstantin.chaika@jetbrains.com> Date: Tue, 19 Dec 2023 16:17:54 +0400 Subject: [PATCH 1/2] Add changes to Functions lesson --- Functions/Args and kwargs/args_kwargs.py | 8 +++-- Functions/Args and kwargs/task-info.yaml | 32 +++++++++---------- Functions/Args and kwargs/task.md | 2 ++ Functions/Default parameters/task.md | 1 + Functions/Definition/task.md | 3 ++ Functions/Docstrings/task.md | 2 ++ .../Parameters and call arguments/task.md | 2 ++ Functions/Recursion/task.md | 2 ++ Functions/Return value/task-info.yaml | 8 ++--- Functions/Return value/task.md | 2 ++ 10 files changed, 38 insertions(+), 24 deletions(-) diff --git a/Functions/Args and kwargs/args_kwargs.py b/Functions/Args and kwargs/args_kwargs.py index 750a191e..9f38b248 100644 --- a/Functions/Args and kwargs/args_kwargs.py +++ b/Functions/Args and kwargs/args_kwargs.py @@ -29,9 +29,11 @@ def cat(food, *args, state='still hungry', action='meow', breed='Siamese'): print(arg.upper()) -# Add a list of phrases that will be capitalized. +# Declare a list of phrases that will be capitalized according the task description phrases = ['It is too fat.', 'You are feeding your cat too much.'] -# Add a dict of keyword arguments. + +# Declare a dict of keyword arguments to insert into the narrative. The keys should match the named arguments of the cat() keywords = {'state': 'fat', 'action': 'eat', 'breed': 'Maine Coon'} -# Call the cat() function like in example above to print the required output. + +# Call the cat() function like in example above with some food, phrases and keywords to print the required output. cat('anything', *phrases, **keywords) diff --git a/Functions/Args and kwargs/task-info.yaml b/Functions/Args and kwargs/task-info.yaml index 79300601..6c52711f 100644 --- a/Functions/Args and kwargs/task-info.yaml +++ b/Functions/Args and kwargs/task-info.yaml @@ -1,19 +1,17 @@ type: edu files: -- name: args_kwargs.py - visible: true - placeholders: - - offset: 1121 - length: 56 - placeholder_text: '# Declare the phrases following the output, like in the task - description' - - offset: 1224 - length: 56 - placeholder_text: '# Declare the keywords to insert into the narrative. The keys - should match the named arguments of the cat()' - - offset: 1359 - length: 37 - placeholder_text: '# invoke cat with some food, phrases and keywords' -- name: tests/test_task.py - visible: false -feedback_link: https://docs.google.com/forms/d/e/1FAIpQLSfRlDlldKfuq-cHMNFfHMER61P1PRIan7KG6yp1GvaweDI7GA/viewform?usp=pp_url&entry.2103429047=Functions+/+Args+and+Kwargs \ No newline at end of file + - name: args_kwargs.py + visible: true + placeholders: + - offset: 1156 + length: 54 + placeholder_text: ??? + - offset: 1348 + length: 54 + placeholder_text: ??? + - offset: 1524 + length: 32 + placeholder_text: ??? + - name: tests/test_task.py + visible: false +feedback_link: https://docs.google.com/forms/d/e/1FAIpQLSfRlDlldKfuq-cHMNFfHMER61P1PRIan7KG6yp1GvaweDI7GA/viewform?usp=pp_url&entry.2103429047=Functions+/+Args+and+Kwargs diff --git a/Functions/Args and kwargs/task.md b/Functions/Args and kwargs/task.md index d658b2f1..4ea180c4 100644 --- a/Functions/Args and kwargs/task.md +++ b/Functions/Args and kwargs/task.md @@ -24,6 +24,8 @@ after the `*args` parameter are [‘keyword-only’](https://peps.python.org/pep rather than positional arguments. Another way to call this function is shown in call 2, and it will give us the same output. +For more structured and detailed information, you can refer to [this ](https://hyperskill.org/learn/step/8560) and [this](https://hyperskill.org/learn/step/9544) Hyperskill knowledge base pages. + ### Task In the code editor, modify the code below the `cat()` function so that it prints diff --git a/Functions/Default parameters/task.md b/Functions/Default parameters/task.md index 66a862ad..772cdd68 100644 --- a/Functions/Default parameters/task.md +++ b/Functions/Default parameters/task.md @@ -19,6 +19,7 @@ Do not put spaces around the `=` symbol in function calls and definitions. Explore this topic further by reading <a href="https://docs.python.org/3/tutorial/controlflow.html#default-argument-values">this section</a> of Python Documentation. +For more structured and detailed information, you can also refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/10295). ### Task Add parameters to the `hello()` function and set a default value for the `name` parameter. diff --git a/Functions/Definition/task.md b/Functions/Definition/task.md index a1c37c12..eea68d8d 100644 --- a/Functions/Definition/task.md +++ b/Functions/Definition/task.md @@ -20,6 +20,9 @@ my_function() # function call ``` Read more about defining functions in <a href="https://docs.python.org/3/tutorial/controlflow.html#defining-functions">this section</a> of Python Documentation. + +For more structured and detailed information, you can also refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/5900). + ### Task - Call the function `my_function` inside the loop to repeat its invocation 5 times - Define a function that can replace the duplicated `print` statements in the file. diff --git a/Functions/Docstrings/task.md b/Functions/Docstrings/task.md index 1df24da4..746f9268 100644 --- a/Functions/Docstrings/task.md +++ b/Functions/Docstrings/task.md @@ -6,6 +6,8 @@ A docstring for a function or method should summarize its behavior and document Docstrings should also generally be written for module, class and method definitions (you will learn about these things later on in the course). Read more about docstring conventions in the [Python PEP Guide](https://peps.python.org/pep-0257/). +For more structured and detailed information, you can also refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/11869). + ### Task Add the following docstring to the function defined in the code editor: ```text diff --git a/Functions/Parameters and call arguments/task.md b/Functions/Parameters and call arguments/task.md index 1bb5e7ae..03cdab29 100644 --- a/Functions/Parameters and call arguments/task.md +++ b/Functions/Parameters and call arguments/task.md @@ -35,6 +35,8 @@ TypeError Traceback (most recent call last) TypeError: my_function() missing 1 required positional argument: 'surname' ``` +For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/7248). + ### Task In the code editor, define a function that prints the square of a passed parameter. diff --git a/Functions/Recursion/task.md b/Functions/Recursion/task.md index 2aae9ea9..835b84c7 100644 --- a/Functions/Recursion/task.md +++ b/Functions/Recursion/task.md @@ -54,6 +54,8 @@ Keep in mind that recursion isn’t useful in every situation. For some problems possible, will be awkward rather than elegant. Recursive implementations often consume more memory than non-recursive ones and in some cases may result in slower execution. +For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/7665). + ### Task In the code editor, implement a recursive function that calculates the [factorial](https://en.wikipedia.org/wiki/Factorial) of a positive integer. For 1 and 0 it returns 1, for every other number it calculates the product of this number (`n`) and diff --git a/Functions/Return value/task-info.yaml b/Functions/Return value/task-info.yaml index cae1f5fb..b73b207d 100644 --- a/Functions/Return value/task-info.yaml +++ b/Functions/Return value/task-info.yaml @@ -5,16 +5,16 @@ files: placeholders: - offset: 364 length: 1 - placeholder_text: '# Assign an initial value to b' + placeholder_text: '# Assign an initial value to b-variable' - offset: 436 length: 9 - placeholder_text: '# Update some value with a sum' + placeholder_text: '# Update b-variable with a sum' - offset: 454 length: 11 - placeholder_text: '# Restore a variable from the temp' + placeholder_text: '# Restore old value of b-variable to a-variable from the temp' - offset: 470 length: 13 - placeholder_text: '# here we need to return the result to the caller' + placeholder_text: '# Here we need to return the result to the caller' - name: tests/test_task.py visible: false - name: tests/decorated_test_function.py diff --git a/Functions/Return value/task.md b/Functions/Return value/task.md index 03823202..e7a2ae93 100644 --- a/Functions/Return value/task.md +++ b/Functions/Return value/task.md @@ -6,6 +6,8 @@ without a `return` statement do return a value. This value is called `None` (it’s a built-in name). Writing the value `None` is normally suppressed by the interpreter, but if you really want to see it, you can use `print(some_func())`. +For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/5900#execution-and-return). + ><i>The first statement of the function body can optionally be a string literal; this string literal is the function’s documentation string, or docstring (more about docstrings can be found in the section <a href="https://docs.python.org/3/tutorial/controlflow.html#tut-docstrings">Documentation Strings</a> From 44511854822286f12fe72d7b734aad583c2e4b91 Mon Sep 17 00:00:00 2001 From: Konstantin Chaika <konstantin.chaika@jetbrains.com> Date: Mon, 15 Jan 2024 14:07:50 +0400 Subject: [PATCH 2/2] Language changes --- Functions/Args and kwargs/args_kwargs.py | 7 ++++--- Functions/Args and kwargs/task-info.yaml | 6 +++--- Functions/Return value/task-info.yaml | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Functions/Args and kwargs/args_kwargs.py b/Functions/Args and kwargs/args_kwargs.py index 9f38b248..e81fcb2b 100644 --- a/Functions/Args and kwargs/args_kwargs.py +++ b/Functions/Args and kwargs/args_kwargs.py @@ -29,11 +29,12 @@ def cat(food, *args, state='still hungry', action='meow', breed='Siamese'): print(arg.upper()) -# Declare a list of phrases that will be capitalized according the task description +# Declare a list of phrases that will be capitalized according to the task description phrases = ['It is too fat.', 'You are feeding your cat too much.'] -# Declare a dict of keyword arguments to insert into the narrative. The keys should match the named arguments of the cat() +# Declare a dict of keyword arguments to insert into the narrative. +# The keys should match the named arguments of the cat() function. keywords = {'state': 'fat', 'action': 'eat', 'breed': 'Maine Coon'} -# Call the cat() function like in example above with some food, phrases and keywords to print the required output. +# Call the cat() function like in the example above, with some food, phrases, and keywords to print the required output. cat('anything', *phrases, **keywords) diff --git a/Functions/Args and kwargs/task-info.yaml b/Functions/Args and kwargs/task-info.yaml index 6c52711f..e3431c0f 100644 --- a/Functions/Args and kwargs/task-info.yaml +++ b/Functions/Args and kwargs/task-info.yaml @@ -3,13 +3,13 @@ files: - name: args_kwargs.py visible: true placeholders: - - offset: 1156 + - offset: 1159 length: 54 placeholder_text: ??? - - offset: 1348 + - offset: 1363 length: 54 placeholder_text: ??? - - offset: 1524 + - offset: 1545 length: 32 placeholder_text: ??? - name: tests/test_task.py diff --git a/Functions/Return value/task-info.yaml b/Functions/Return value/task-info.yaml index b73b207d..0468c58c 100644 --- a/Functions/Return value/task-info.yaml +++ b/Functions/Return value/task-info.yaml @@ -5,13 +5,13 @@ files: placeholders: - offset: 364 length: 1 - placeholder_text: '# Assign an initial value to b-variable' + placeholder_text: '# Assign an initial value to the b variable' - offset: 436 length: 9 - placeholder_text: '# Update b-variable with a sum' + placeholder_text: '# Update the b variable with a sum' - offset: 454 length: 11 - placeholder_text: '# Restore old value of b-variable to a-variable from the temp' + placeholder_text: '# Restore the old value of the b variable to the a variable from the temp' - offset: 470 length: 13 placeholder_text: '# Here we need to return the result to the caller'