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

Functions changes #225

Merged
merged 2 commits into from
Jan 23, 2024
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
9 changes: 6 additions & 3 deletions Functions/Args and kwargs/args_kwargs.py
Original file line number Diff line number Diff line change
@@ -29,9 +29,12 @@ 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 to 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() function.
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 the example above, with some food, phrases, and keywords to print the required output.
cat('anything', *phrases, **keywords)
32 changes: 15 additions & 17 deletions Functions/Args and kwargs/task-info.yaml
Original file line number Diff line number Diff line change
@@ -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
- name: args_kwargs.py
visible: true
placeholders:
- offset: 1159
length: 54
placeholder_text: ???
- offset: 1363
length: 54
placeholder_text: ???
- offset: 1545
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
2 changes: 2 additions & 0 deletions Functions/Args and kwargs/task.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Functions/Default parameters/task.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions Functions/Definition/task.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions Functions/Docstrings/task.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions Functions/Parameters and call arguments/task.md
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 2 additions & 0 deletions Functions/Recursion/task.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions Functions/Return value/task-info.yaml
Original file line number Diff line number Diff line change
@@ -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 the b variable'
- offset: 436
length: 9
placeholder_text: '# Update some value with a sum'
placeholder_text: '# Update the b variable with a sum'
- offset: 454
length: 11
placeholder_text: '# Restore 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'
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
2 changes: 2 additions & 0 deletions Functions/Return value/task.md
Original file line number Diff line number Diff line change
@@ -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>