This module focuses on Python namespaces and functions, including function parameters, call counting, recursion, and unpacking arguments.
- Solution
- Description:
Task "Call Counter"
- Write 3 functions:
count_calls
: Tracks how many times other functions are called.string_info
: Takes a string and returns a tuple containing its length, uppercase version, and lowercase version.is_contains
: Takes a string and a list, returning True if the string is in the list (case-insensitive), False otherwise.
- Track the number of times the functions are called using a counter.
- Write 3 functions:
- Solution
- Description:
Task "Email Sending":
- Create a function
send_email
with parameters for message, recipient, and a named argument for sender with a default value. - Implement logic to check if emails are valid, prevent sending an email to oneself, and differentiate between default and custom senders.
- Create a function
- Solution
- Description:
Task "Unpacking":
- Create a function
print_params
with default parameters, test it with various argument combinations, and demonstrate the use of argument unpacking from lists and dictionaries.
- Create a function
- Solution
- Description:
Task "Single Root Words":
- Write a function
single_root_words
that accepts a root word and a variable number of additional words, returning a list of words that either contain the root word or are contained by it.
- Write a function
- Solution
- Description:
Task "Recursive Digit Multiplication":
- Write a recursive function
get_multiplied_digits
that calculates the product of the digits of a given number.
- Write a recursive function
- Solution
- Description:
Task "One, Two, Three, Four... Is That All?":
- Write a function that calculates the sum of all numbers and the lengths of all strings in a nested data structure, which may include lists, dictionaries, and tuples.